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 SQL onComplete flag, allow sql migration to run with others #280

Merged
merged 25 commits into from
Feb 12, 2024

Conversation

exekias
Copy link
Member

@exekias exekias commented Feb 7, 2024

This change updates the sql operation to:

  • Allow for a new onComplete flag, that will make it run on the Complete phase, rather than doing it during Start (default behavior).
  • Allows for sql operations next to others in the same migration. We added this limitation to ensure this operation doesn't affect others, especially around schema state management.

Having sql next to other operations has proven convenient sometimes, by adding onComplete flag, we can allow for these migrations to run and rely on views recreation based on the final state.

by default, SQL migrations run on start. This change allows for special
SQL migrations that run only on the complete step.
@exekias exekias marked this pull request as draft February 7, 2024 16:24
@exekias exekias marked this pull request as ready for review February 8, 2024 16:28
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

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

It looks good. I left a lot of small comments.

docs/README.md Outdated Show resolved Hide resolved
docs/README.md Outdated Show resolved Hide resolved
pkg/migrations/migrations.go Outdated Show resolved Hide resolved
pkg/migrations/migrations_test.go Outdated Show resolved Hide resolved
pkg/migrations/migrations.go Show resolved Hide resolved
pkg/migrations/op_raw_sql.go Outdated Show resolved Hide resolved
pkg/migrations/op_raw_sql_test.go Outdated Show resolved Hide resolved
pkg/migrations/op_raw_sql_test.go Outdated Show resolved Hide resolved
// we don't want to refresh the schema if the operation is not isolated as it would
// override changes made by other operations
if refreshOp, ok := op.(migrations.RequiresSchemaRefreshOperation); ok && refreshOp.RequiresSchemaRefresh() {
if isolatedOp, ok := op.(migrations.IsolatedOperation); ok && isolatedOp.IsIsolated() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we now only refresh schema for ops that are both RequiresSchemaRefreshOperation and IsolatedOperation rather than just RequiresSchemaRefreshOperation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Main reason is: that it could be non-isolated & require schema refresh. That's the case for migrations with onComplete.

Migrations that are not isolated & require a schema refresh on Start phase would surely break others, as it would override the resulting schema from the start ops, by refreshing it afterwards. I tried to capture this in the comment

pkg/roll/execute.go Show resolved Hide resolved
examples/32_sql_onComplete.json Outdated Show resolved Hide resolved
pkg/jsonschema/testdata/sql-3.txtar Outdated Show resolved Hide resolved
pkg/jsonschema/testdata/sql-4.txtar Outdated Show resolved Hide resolved
pkg/jsonschema/testdata/sql-4.txtar Outdated Show resolved Hide resolved
docs/README.md Show resolved Hide resolved
docs/README.md Outdated Show resolved Hide resolved
@exekias exekias merged commit 58fa7ae into main Feb 12, 2024
34 checks passed
@exekias exekias deleted the sql-on-complete branch February 12, 2024 15:37
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