-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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(core): Disallow orphan executions #7069
Merged
+85
−8
Merged
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9adc4cc
refactor: Disallow orphan executions
ivov a377768
Add backticks for MySQL
ivov 022bee2
Revert "Add backticks for MySQL"
ivov b41180c
Fix silly mistake
ivov c621ec7
Merge branch 'master' into disallow-orphan-executions
ivov 672d2d7
Add indices
ivov 3ed4afe
Merge branch 'master' into disallow-orphan-executions
ivov af7d7d2
feat(core): Add new DSL for adding and dropping `NOT NULL` constraint…
netroy 50fb9ea
feat(core): Add new DSL for adding and dropping `NOT NULL` constraint…
netroy ea5569b
Merge branch 'DSL-dropNotNull' into disallow-orphan-executions
ivov 7cc3edd
refactor: Disallow orphan executions
ivov 7164645
Add backticks for MySQL
ivov a797bcf
Revert "Add backticks for MySQL"
ivov 9052696
Fix silly mistake
ivov 5db2111
Add indices
ivov a07ecd5
Simplify using DSL updates
ivov 5735388
use consistent order of fields in DSL methods
netroy a7eca82
DSL exceptions should reject the lazy promise
netroy ed5ca4b
Update 1693554410387-DisallowOrphanExecutions.ts
netroy c8c3510
Merge branch 'DSL-dropNotNull' into disallow-orphan-executions
ivov d21401b
Cleanup
ivov e9f3753
Merge branch 'master' into disallow-orphan-executions
ivov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/cli/src/databases/migrations/mysqldb/1693554410387-DisallowOrphanExecutions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { MigrationContext, ReversibleMigration } from '@db/types'; | ||
|
||
export class DisallowOrphanExecutions1693554410387 implements ReversibleMigration { | ||
/** | ||
* Ensure all executions point to a workflow. | ||
*/ | ||
async up({ queryRunner, escape }: MigrationContext) { | ||
const executionEntity = escape.tableName('execution_entity'); | ||
const workflowId = escape.columnName('workflowId'); | ||
|
||
await queryRunner.query(`DELETE FROM ${executionEntity} WHERE ${workflowId} IS NULL;`); | ||
await queryRunner.query( | ||
`ALTER TABLE ${executionEntity} MODIFY ${workflowId} VARCHAR(36) NOT NULL;`, | ||
); | ||
} | ||
|
||
/** | ||
* Reversal excludes restoring deleted rows. | ||
*/ | ||
async down({ queryRunner, escape }: MigrationContext) { | ||
const executionEntity = escape.tableName('execution_entity'); | ||
const workflowId = escape.columnName('workflowId'); | ||
|
||
await queryRunner.query(`ALTER TABLE ${executionEntity} MODIFY ${workflowId} VARCHAR(36);`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/cli/src/databases/migrations/postgresdb/1693554410387-DisallowOrphanExecutions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { MigrationContext, ReversibleMigration } from '@db/types'; | ||
|
||
export class DisallowOrphanExecutions1693554410387 implements ReversibleMigration { | ||
/** | ||
* Ensure all executions point to a workflow. | ||
*/ | ||
async up({ queryRunner, escape }: MigrationContext) { | ||
const executionEntity = escape.tableName('execution_entity'); | ||
const workflowId = escape.columnName('workflowId'); | ||
|
||
await queryRunner.query(`DELETE FROM ${executionEntity} WHERE ${workflowId} IS NULL;`); | ||
await queryRunner.query( | ||
`ALTER TABLE ${executionEntity} ALTER COLUMN ${workflowId} SET NOT NULL;`, | ||
); | ||
} | ||
|
||
/** | ||
* Reversal excludes restoring deleted rows. | ||
*/ | ||
async down({ queryRunner, escape }: MigrationContext) { | ||
const executionEntity = escape.tableName('execution_entity'); | ||
const workflowId = escape.columnName('workflowId'); | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE ${executionEntity} ALTER COLUMN ${workflowId} DROP NOT NULL;`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/cli/src/databases/migrations/sqlite/1693554410387-DisallowOrphanExecutions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { MigrationContext, ReversibleMigration } from '@db/types'; | ||
|
||
export class DisallowOrphanExecutions1693554410387 implements ReversibleMigration { | ||
transaction = false as const; | ||
|
||
/** | ||
* Ensure all executions point to a workflow. Recreate table because sqlite | ||
* does not support modifying column. | ||
*/ | ||
async up({ escape, schemaBuilder: { createTable, column }, runQuery }: MigrationContext) { | ||
const executionEntity = escape.tableName('execution_entity'); | ||
const workflowId = escape.columnName('workflowId'); | ||
|
||
await runQuery(`DELETE FROM ${executionEntity} WHERE ${workflowId} IS NULL;`); | ||
|
||
await createTable('temp') | ||
.withColumns( | ||
column('id').int.primary.autoGenerate.notNull, | ||
column('workflowId').varchar(36).notNull, // only change | ||
column('finished').bool.notNull, | ||
column('mode').varchar().notNull, | ||
column('retryOf').varchar(), | ||
column('retrySuccessId').varchar(), | ||
column('startedAt').timestamp().notNull, | ||
column('stoppedAt').timestamp(), | ||
column('waitTill').timestamp(), | ||
column('status').varchar(), | ||
) | ||
.withForeignKey('workflowId', { | ||
tableName: 'workflow_entity', | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}); | ||
ivov marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will require recreating the indexes as well I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see 672d2d7 |
||
|
||
await runQuery( | ||
`INSERT INTO "temp" ("id", "workflowId", "finished", "mode", "retryOf", "retrySuccessId", "startedAt", "stoppedAt", "waitTill", "status") SELECT "id", "workflowId", "finished", "mode", "retryOf", "retrySuccessId", "startedAt", "stoppedAt", "waitTill", "status" FROM ${executionEntity};`, | ||
); | ||
|
||
await runQuery(`DROP TABLE ${executionEntity};`); | ||
ivov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await runQuery(`ALTER TABLE "temp" RENAME TO ${executionEntity};`); | ||
} | ||
|
||
/** | ||
* Reversal excludes restoring deleted rows. | ||
*/ | ||
async down({ escape, schemaBuilder: { createTable, column }, runQuery }: MigrationContext) { | ||
const executionEntity = escape.tableName('execution_entity'); | ||
|
||
await createTable('temp') | ||
.withColumns( | ||
column('id').int.primary.autoGenerate.notNull, | ||
column('workflowId').varchar(36), // only change | ||
column('finished').bool.notNull, | ||
column('mode').varchar().notNull, | ||
column('retryOf').varchar(), | ||
column('retrySuccessId').varchar(), | ||
column('startedAt').timestamp().notNull, | ||
column('stoppedAt').timestamp(), | ||
column('waitTill').timestamp(), | ||
column('status').varchar(), | ||
) | ||
.withForeignKey('workflowId', { | ||
tableName: 'workflow_entity', | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}); | ||
|
||
await runQuery( | ||
`INSERT INTO "temp" ("id", "workflowId", "finished", "mode", "retryOf", "retrySuccessId", "startedAt", "stoppedAt", "waitTill", "status") SELECT "id", "workflowId", "finished", "mode", "retryOf", "retrySuccessId", "startedAt", "stoppedAt", "waitTill", "status" FROM ${executionEntity};`, | ||
); | ||
|
||
await runQuery(`DROP TABLE ${executionEntity};`); | ||
|
||
await runQuery(`ALTER TABLE "temp" RENAME TO ${executionEntity};`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why not combine the 3 migrations into a single one?
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.
How do you mean? The syntax to modify a column differs between MySQL and Postgres, and sqlite requires recreating the table, and it looks like the DSL does not support this yet.