refactor(core): Delete more redundant code across migrations (Part 1) (no-changelog) (#6691)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-07-31 17:35:53 +02:00
committed by GitHub
parent 7b27fa5898
commit b7ca27afcf
42 changed files with 830 additions and 2195 deletions

View File

@@ -1,53 +1,3 @@
import type { MigrationContext, ReversibleMigration } from '@db/types';
import { StatisticsNames } from '@db/entities/WorkflowStatistics';
import { RemoveWorkflowDataLoadedFlag1671726148419 } from '../common/1671726148419-RemoveWorkflowDataLoadedFlag';
export class RemoveWorkflowDataLoadedFlag1671726148421 implements ReversibleMigration {
async up({ queryRunner, tablePrefix }: MigrationContext) {
// If any existing workflow has dataLoaded set to true, insert the relevant information to the statistics table
const workflowIds = (await queryRunner.query(`
SELECT id, "dataLoaded"
FROM ${tablePrefix}workflow_entity
`)) as Array<{ id: number; dataLoaded: boolean }>;
workflowIds.map(async ({ 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"`);
}
async down({ queryRunner, tablePrefix }: MigrationContext) {
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 = (await queryRunner.query(`
SELECT "workflowId"
FROM ${tablePrefix}workflow_statistics
WHERE name = '${StatisticsNames.dataLoaded}'
`)) as Array<{ workflowId: string }>;
workflowsIds.map(async ({ 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}'`,
);
}
}
export class RemoveWorkflowDataLoadedFlag1671726148421 extends RemoveWorkflowDataLoadedFlag1671726148419 {}