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,31 +1,3 @@
import type { MigrationContext, ReversibleMigration } from '@db/types';
import { v4 as uuidv4 } from 'uuid';
import { AddWorkflowVersionIdColumn1669739707124 } from '../common/1669739707124-AddWorkflowVersionIdColumn';
export class AddWorkflowVersionIdColumn1669739707126 implements ReversibleMigration {
async up({ queryRunner, tablePrefix }: MigrationContext) {
await queryRunner.query(
`ALTER TABLE ${tablePrefix}workflow_entity ADD COLUMN "versionId" CHAR(36)`,
);
const workflowIds = (await queryRunner.query(`
SELECT id
FROM ${tablePrefix}workflow_entity
`)) as Array<{ id: number }>;
for (const { id } of workflowIds) {
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
`UPDATE ${tablePrefix}workflow_entity
SET "versionId" = :versionId
WHERE id = '${id}'`,
{ versionId: uuidv4() },
{},
);
await queryRunner.query(updateQuery, updateParams);
}
}
async down({ queryRunner, tablePrefix }: MigrationContext) {
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "versionId"`);
}
}
export class AddWorkflowVersionIdColumn1669739707126 extends AddWorkflowVersionIdColumn1669739707124 {}