-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Fixes issue with workflow lastUpdated field (#5015)
Fixed issue causing workflow updated field to be affected by statistics data
- Loading branch information
freya
authored
Jan 5, 2023
1 parent
7954025
commit 59004fe
Showing
16 changed files
with
263 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
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
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
66 changes: 66 additions & 0 deletions
66
packages/cli/src/databases/migrations/mysqldb/1671726148420-RemoveWorkflowDataLoadedFlag.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,66 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers'; | ||
import config from '@/config'; | ||
import { StatisticsNames } from '@/databases/entities/WorkflowStatistics'; | ||
|
||
export class RemoveWorkflowDataLoadedFlag1671726148420 implements MigrationInterface { | ||
name = 'RemoveWorkflowDataLoadedFlag1671726148420'; | ||
|
||
async up(queryRunner: QueryRunner) { | ||
logMigrationStart(this.name); | ||
const tablePrefix = config.getEnv('database.tablePrefix'); | ||
|
||
// If any existing workflow has dataLoaded set to true, insert the relevant information to the statistics table | ||
const workflowIds: Array<{ id: number; dataLoaded: boolean }> = await queryRunner.query(` | ||
SELECT id, dataLoaded | ||
FROM ${tablePrefix}workflow_entity | ||
`); | ||
|
||
workflowIds.map(({ id, dataLoaded }) => { | ||
if (dataLoaded) { | ||
const [insertQuery, insertParams] = queryRunner.connection.driver.escapeQueryWithParameters( | ||
` | ||
INSERT INTO ${tablePrefix}workflow_statistics (workflowId, name, count, latestEvent) VALUES | ||
(:id, :name, 1, CURRENT_TIMESTAMP(3)) | ||
`, | ||
{ id, name: StatisticsNames.dataLoaded }, | ||
{}, | ||
); | ||
|
||
return queryRunner.query(insertQuery, insertParams); | ||
} | ||
return undefined; | ||
}); | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN dataLoaded`, | ||
); | ||
|
||
logMigrationEnd(this.name); | ||
} | ||
|
||
async down(queryRunner: QueryRunner) { | ||
const tablePrefix = config.getEnv('database.tablePrefix'); | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE ${tablePrefix}workflow_entity ADD COLUMN dataLoaded BOOLEAN DEFAULT false`, | ||
); | ||
|
||
// Search through statistics for any workflows that have the dataLoaded stat | ||
const workflowsIds: Array<{ workflowId: string }> = await queryRunner.query(` | ||
SELECT workflowId | ||
FROM ${tablePrefix}workflow_statistics | ||
WHERE name = '${StatisticsNames.dataLoaded}' | ||
`); | ||
workflowsIds.map(({ workflowId }) => { | ||
return queryRunner.query(` | ||
UPDATE ${tablePrefix}workflow_entity | ||
SET dataLoaded = true | ||
WHERE id = '${workflowId}'`); | ||
}); | ||
|
||
await queryRunner.query( | ||
`DELETE FROM ${tablePrefix}workflow_statistics WHERE name = '${StatisticsNames.dataLoaded}'`, | ||
); | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
...ges/cli/src/databases/migrations/postgresdb/1671726148421-RemoveWorkflowDataLoadedFlag.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,64 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers'; | ||
import config from '@/config'; | ||
import { StatisticsNames } from '@/databases/entities/WorkflowStatistics'; | ||
|
||
export class RemoveWorkflowDataLoadedFlag1671726148421 implements MigrationInterface { | ||
name = 'RemoveWorkflowDataLoadedFlag1671726148421'; | ||
|
||
async up(queryRunner: QueryRunner) { | ||
logMigrationStart(this.name); | ||
const tablePrefix = getTablePrefix(); | ||
|
||
// If any existing workflow has dataLoaded set to true, insert the relevant information to the statistics table | ||
const workflowIds: Array<{ id: number; dataLoaded: boolean }> = await queryRunner.query(` | ||
SELECT id, "dataLoaded" | ||
FROM ${tablePrefix}workflow_entity | ||
`); | ||
|
||
workflowIds.map(({ id, dataLoaded }) => { | ||
if (dataLoaded) { | ||
const [insertQuery, insertParams] = queryRunner.connection.driver.escapeQueryWithParameters( | ||
` | ||
INSERT INTO ${tablePrefix}workflow_statistics ("workflowId", name, count, "latestEvent") VALUES | ||
(:id, :name, 1, CURRENT_TIMESTAMP(3)) | ||
`, | ||
{ id, name: StatisticsNames.dataLoaded }, | ||
{}, | ||
); | ||
|
||
return queryRunner.query(insertQuery, insertParams); | ||
} | ||
return undefined; | ||
}); | ||
|
||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "dataLoaded"`); | ||
|
||
logMigrationEnd(this.name); | ||
} | ||
|
||
async down(queryRunner: QueryRunner) { | ||
const tablePrefix = getTablePrefix(); | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE ${tablePrefix}workflow_entity ADD COLUMN "dataLoaded" BOOLEAN DEFAULT false`, | ||
); | ||
|
||
// Search through statistics for any workflows that have the dataLoaded stat | ||
const workflowsIds: Array<{ workflowId: string }> = await queryRunner.query(` | ||
SELECT "workflowId" | ||
FROM ${tablePrefix}workflow_statistics | ||
WHERE name = '${StatisticsNames.dataLoaded}' | ||
`); | ||
workflowsIds.map(({ workflowId }) => { | ||
return queryRunner.query(` | ||
UPDATE ${tablePrefix}workflow_entity | ||
SET "dataLoaded" = true | ||
WHERE id = '${workflowId}'`); | ||
}); | ||
|
||
await queryRunner.query( | ||
`DELETE FROM ${tablePrefix}workflow_statistics WHERE name = '${StatisticsNames.dataLoaded}'`, | ||
); | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
packages/cli/src/databases/migrations/sqlite/1671726148419-RemoveWorkflowDataLoadedFlag.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,67 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers'; | ||
import config from '@/config'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { StatisticsNames } from '@/databases/entities/WorkflowStatistics'; | ||
|
||
export class RemoveWorkflowDataLoadedFlag1671726148419 implements MigrationInterface { | ||
name = 'RemoveWorkflowDataLoadedFlag1671726148419'; | ||
|
||
async up(queryRunner: QueryRunner) { | ||
logMigrationStart(this.name); | ||
const tablePrefix = config.getEnv('database.tablePrefix'); | ||
|
||
// If any existing workflow has dataLoaded set to true, insert the relevant information to the statistics table | ||
const workflowIds: Array<{ id: number; dataLoaded: boolean }> = await queryRunner.query(` | ||
SELECT id, dataLoaded | ||
FROM "${tablePrefix}workflow_entity" | ||
`); | ||
|
||
workflowIds.map(({ id, dataLoaded }) => { | ||
if (dataLoaded) { | ||
const [insertQuery, insertParams] = queryRunner.connection.driver.escapeQueryWithParameters( | ||
` | ||
INSERT INTO "${tablePrefix}workflow_statistics" (workflowId, name, count, latestEvent) VALUES | ||
(:id, :name, 1, STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')) | ||
`, | ||
{ id, name: StatisticsNames.dataLoaded }, | ||
{}, | ||
); | ||
|
||
return queryRunner.query(insertQuery, insertParams); | ||
} | ||
return undefined; | ||
}); | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE \`${tablePrefix}workflow_entity\` DROP COLUMN "dataLoaded"`, | ||
); | ||
|
||
logMigrationEnd(this.name); | ||
} | ||
|
||
async down(queryRunner: QueryRunner) { | ||
const tablePrefix = config.getEnv('database.tablePrefix'); | ||
|
||
await queryRunner.query( | ||
`ALTER TABLE \`${tablePrefix}workflow_entity\` ADD COLUMN "dataLoaded" BOOLEAN DEFAULT false`, | ||
); | ||
|
||
// Search through statistics for any workflows that have the dataLoaded stat | ||
const workflowsIds: Array<{ workflowId: string }> = await queryRunner.query(` | ||
SELECT workflowId | ||
FROM "${tablePrefix}workflow_statistics" | ||
WHERE name = '${StatisticsNames.dataLoaded}' | ||
`); | ||
workflowsIds.map(({ workflowId }) => { | ||
return queryRunner.query(` | ||
UPDATE "${tablePrefix}workflow_entity" | ||
SET dataLoaded = true | ||
WHERE id = '${workflowId}'`); | ||
}); | ||
|
||
await queryRunner.query( | ||
`DELETE FROM "${tablePrefix}workflow_statistics" WHERE name = '${StatisticsNames.dataLoaded}'`, | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.