Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jefferai
Copy link
Member

@jefferai jefferai commented Mar 5, 2021

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.

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.
@jefferai jefferai added this to the 0.1.8 milestone Mar 5, 2021
Copy link
Contributor

@talanknight talanknight left a 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 {
Copy link
Contributor

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.

Copy link
Member Author

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.
Copy link
Contributor

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.

Copy link
Contributor

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.

@malnick malnick removed this from the 0.1.8 milestone Mar 9, 2021
@jefferai jefferai added this to the deferred milestone Mar 24, 2021
@jefferai jefferai marked this pull request as draft March 30, 2021 18:33
louisruch pushed a commit that referenced this pull request Apr 7, 2024
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants