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

feat: database migrations #3457

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

stuartwdouglas
Copy link
Collaborator

No description provided.

This was referenced Nov 22, 2024
@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/migrations branch 2 times, most recently from 3f5877b to ec9f01d Compare November 22, 2024 02:59
@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/migrations branch 9 times, most recently from d58d4a6 to 7aa111b Compare November 22, 2024 06:40
@stuartwdouglas stuartwdouglas marked this pull request as ready for review November 22, 2024 07:32
@stuartwdouglas stuartwdouglas requested review from wesbillman and removed request for a team November 22, 2024 07:32
@stuartwdouglas stuartwdouglas requested a review from a team as a code owner November 22, 2024 07:51
@stuartwdouglas stuartwdouglas requested review from worstell and removed request for a team November 22, 2024 07:51
@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/migrations branch 2 times, most recently from e88667f to d4f0282 Compare November 22, 2024 08:31
@@ -41,6 +42,12 @@ message MysqlResource {
MysqlResourceOutput output = 1;
}

message MigrationResource {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix all these types/functions with "SQL", "migrations" is not specific enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify why I think this is important - it's very likely there will be other kinds of migrations in the future.

backend/provisioner/migration_provisioner.go Outdated Show resolved Hide resolved
backend/provisioner/registry.go Outdated Show resolved Hide resolved
Schema *schema.Schema
Dependencies []string
BuildEnv []string
AdditionalFiles []string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 95% sure this should just be part of the ModuleConfig .proto rather than here (cc @matt2e) - this is exactly what it's designed for. Each language plugin then just returns the directory for any migrations, and the build engine does the bundling rather than each runtime having to have custom logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if we wanted the build engine to modify the schema after the language plugin was finished with it. I can definitely change it but I think it does kinda blur the lines about what is responsible for generating the schema.

I figured language plugins could just re-use the ExtractMigrations function and achieve re-use that way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a requirement that language plugins be in Go, and in general we try to push as much as possible out of the plugins and into the engine for this reason.

The pattern is that the ModuleConfig tells the BuildEngine where to look for different parts of the build, and the BuildEngine does the work of collecting it into the schema+build. This fits that fairly well. It could be a glob, or a regex, or a map of db names to paths or something.

internal/migration/extract_migration.go Outdated Show resolved Hide resolved
internal/migration/extract_migration_test.go Show resolved Hide resolved
targetDir := t.TempDir()

// Create dummy migration files
migrationSubDir := filepath.Join(migrationsDir, "testdb")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to use testdata for the fixtures?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was just for integration tests? Also it's possible Chad may have written this test...

internal/schema/parser.go Outdated Show resolved Hide resolved
@@ -729,6 +731,7 @@ module todo {
secret secretValue String
// A database
database postgres testdb
+migration sha256:8cc04c75ab7967eb2ec82e11e886831e00b7cb00507e9a8ecf400bdc599eccfd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice.

switch md := md.(type) {
case *MetadataMigration:
if found {
merr = append(merr, fmt.Errorf("database %q has multiple migration metadata", n.Name))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah nice.

@stuartwdouglas stuartwdouglas force-pushed the stuartwdouglas/migrations branch 3 times, most recently from 8fb80c3 to e03fdd8 Compare November 23, 2024 03:10
@stuartwdouglas
Copy link
Collaborator Author

I think I have addressed everything, except for the questions around if this should be handled by the build engine or language plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants