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

Fix migration validation issue #6154

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void migrate(Context context) throws Exception {
// As database schema changes, the generated jOOQ code can be deprecated. So
// old migration may not compile if there is any generated code.
DSLContext ctx = DSL.using(context.getConnection());
ctx.alterTable("attempts").addColumn(DSL.field("temporal_workflow_id", SQLDataType.VARCHAR(256).nullable(true)))
ctx.alterTable("attempts")
.addColumnIfNotExists(DSL.field("temporal_workflow_id", SQLDataType.VARCHAR(256).nullable(true)))
Copy link
Contributor Author

@tuliren tuliren Sep 16, 2021

Choose a reason for hiding this comment

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

This is not necessary. But I feel that we should be extra cautious now. This change makes the migration idempotent. Even if the user's database is in a weird state (e.g. this column is manually added), it will work.

.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ required:
- status
- created_at
- updated_at
additionalProperties: false
additionalProperties: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make the attempts schema forward compatible before the file-based migration system is removed.

properties:
id:
type: number
Expand All @@ -25,8 +25,6 @@ properties:
type: ["null", object]
status:
type: string
temporal_workflow_id:
type: ["null", string]
Copy link
Contributor Author

@tuliren tuliren Sep 16, 2021

Choose a reason for hiding this comment

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

This schema is used for validation in the file-based migration system, which does not know the existence of this property created by Flyway.

created_at:
# todo should be datetime.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ required:
- status
- created_at
- updated_at
additionalProperties: false
additionalProperties: true
properties:
id:
type: number
Expand Down