-
Notifications
You must be signed in to change notification settings - Fork 292
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
Add migration hooks to allow Go functions to be run #985
base: main
Are you sure you want to change the base?
Conversation
These can be run before or after migrations. This should be seen as anticipatory. There isn't really much added logic, it mostly reorganizes what's there.
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 looks like it'll be very helpful for allowing go logic to modify db state in the current migration process. It is a little difficult to see how it'll look and how easy it'll be to maintain in practice without an example. I've added just a few comments to spur discussion.
@@ -191,9 +193,20 @@ func (b *Manager) runMigrations(ctx context.Context, qp *statementProvider) erro | |||
default: | |||
// context is not done yet. Continue on to the next query to execute. | |||
} | |||
if err := b.driver.Run(ctx, bytes.NewReader(qp.ReadUp()), qp.Version()); err != nil { | |||
upVer := qp.ReadUp() | |||
if upVer.PreHook != nil { |
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.
Instead of Pre/Post hooks, what if we decoupled them completely from a statement version? What I am envisioning would be each version could be either an SQL statement that is passed to driver.Run(ctx, ...) or a goFunction that is passed to something like driver.ExecuteFn(ctx, migrateFunction) but not both.
The benefit of this approach, in my opinion, is that it allows the sql.Tx to not have to be exported since there may be a db in the future that we rely on dirty bits instead of transactions. It also makes the migration steps a little easier to reason about since you can just step through each migration version sequentially.
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 to make sure I'm understanding, you are suggesting that rather than pass statements, that we encapsulate the entirety of a version in a Go function? That way a "basic" update function would just execute the statements, but then rather than pre/post hooks we can just mix in logic as needed?
`{{ .Name }}: { | ||
Statements: []byte(` + "`\n{{ .Content }}\n`" + `), | ||
}, | ||
`)).New("MainPage").Parse(`// Code generated by "make migrations"; DO NOT EDIT. |
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.
Having this comment above the package makes it a package comment, but this is generated to a package where not every file is auto generated.
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.
Oh, sorry. I see now you moved it to its own package.
…ng the db has no issues with removing the storage bucket. This prevents the plugin from deleting rotated credentials while session recordings still exist in the bucket. (#985) Co-authored-by: Danielle Miu <[email protected]>
These can be run before or after migrations. This should be seen as
anticipatory. There isn't really much added logic, it mostly reorganizes
what's there.