-
-
Notifications
You must be signed in to change notification settings - Fork 234
Refactor grant_tables
to mysql_db
#1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
grant_tables
to mysql_db
grant_tables
to mysql_db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach seems fine, model for flatbuffer messages looks reasonable to me. Daylon should take a look.
grant_tables
to mysql_db
grant_tables
to mysql_db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! A few things to cleanup and I think it's good to go.
sql/mysql_db/mysql_db.go
Outdated
func (g *GrantTables) LoadData(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error { | ||
g.Enabled = true | ||
func (t *MySQLDb) LoadPrivilegeData(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error { | ||
// TODO: this is bad do something else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random comment? Looks like some leftovers, I'd remove if it's no longer relevant.
sql/mysql_db/mysql_db.go
Outdated
g.persistFunc = persistFunc | ||
// loadPrivilegeTypes is a helper method that loads privilege types given the length and loading function | ||
// and returns them as a set | ||
func loadPrivilegeTypes(n int, f func(j int) int32) map[sql.PrivilegeType]struct{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These load...
functions should be in their own file.
sql/mysql_db/mysql_db.go
Outdated
// persisted. | ||
type PersistCallback func(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error | ||
type PrivilegePersistCallback func(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error | ||
type DataPersistCallback func(ctx *sql.Context, users []*User, roleConnections []*RoleEdge) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see what you were trying to get at here. If an integrator only has privileges (such as a database before this change), then they should still call DataPersistCallback
, and they'll just pass nil
s to the other parameters. Having two callbacks that are functionally equivalent will complicate things.
This also extends to the LoadMySQLData
call, we should only have this one and not the other one for privileges as well.
sql/mysql_db/fbs/mysql_db.fbs
Outdated
|
||
table PrivilegeSet { | ||
global_static:[int]; | ||
//TODO: global_dynamic:[string]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global_dynamic
is fine as a string array. They'll all be unique entries so it'll be fine.
sql/mysql_db/fbs/mysql_db.fbs
Outdated
password:string; | ||
password_last_changed:int64; // time.Time? | ||
locked:bool; | ||
//attributes:string; // *string? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So since FlatBuffers don't support *string
directly, you can mimic it with a struct. See https://stackoverflow.com/questions/53803880/flatbuffers-and-null-value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, password_last_changed
is fine as an int64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at dolthub/dolt#3411 (review), we should make a few changes detailed in that review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A few small comments and we're good to merge
sql/mysql_db/mysql_db.go
Outdated
) | ||
|
||
// PersistCallback represents the callback that will be called when the Grant Tables have been updated and need to be | ||
// PrivilegePersistCallback represents the callback that will be called when the Grant Tables have been updated and need to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong comment name
sql/mysql_db/mysql_db.go
Outdated
// TODO: fill in other tables when they exist | ||
return nil | ||
} | ||
|
||
// SetPersistCallback sets the callback to be used when the Grant Tables have been updated and need to be persisted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't update the comment here, still says Grant Tables
sql/mysql_db/mysql_db.go
Outdated
persistFunc := g.persistFunc | ||
if persistFunc == nil { | ||
func (t *MySQLDb) Persist(ctx *sql.Context) error { | ||
// TODO: future databases will no longer persist to privilege file, only to mysql.db; should document this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Dolt comment, shouldn't be in GMS
return serial.PrivilegeSetEnd(b) | ||
} | ||
|
||
func serializeAttributes(b *flatbuffers.Builder, attributes *string) flatbuffers.UOffsetT { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably leave a comment explaining why the zero offset is necessary, and also that this should always be called as a result
Mostly renaming variables and files to better reflect what they are now.
Added flatbuffer files for MySQL DB.