refactor: Reactivate workflow locking (#4770)
* feat: Reenable workflow locking Co-authored-by: freyamade <freya@n8n.io> Co-authored-by: Csaba Tuncsik <csaba@n8n.io>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import config from '@/config';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
export class AddWorkflowVersionIdColumn1669739707126 implements MigrationInterface {
|
||||
name = 'AddWorkflowVersionIdColumn1669739707126';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}workflow_entity ADD COLUMN "versionId" CHAR(36)`,
|
||||
);
|
||||
|
||||
const workflowIds: Array<{ id: number }> = await queryRunner.query(`
|
||||
SELECT id
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
`);
|
||||
|
||||
workflowIds.map(({ id }) => {
|
||||
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE ${tablePrefix}workflow_entity
|
||||
SET "versionId" = :versionId
|
||||
WHERE id = '${id}'
|
||||
`,
|
||||
{ versionId: uuidv4() },
|
||||
{},
|
||||
);
|
||||
|
||||
return queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "versionId"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user