refactor(core): Delete boilerplate code across migrations (no-changelog) (#5254)
This commit is contained in:
committed by
GitHub
parent
d5c44987f4
commit
82fe6383ef
@@ -1,41 +1,29 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class InitialMigration1587669153312 implements MigrationInterface {
|
||||
name = 'InitialMigration1587669153312';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class InitialMigration1587669153312 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE IF NOT EXISTS ${tablePrefix}credentials_entity ("id" SERIAL NOT NULL, "name" character varying(128) NOT NULL, "data" text NOT NULL, "type" character varying(32) NOT NULL, "nodesAccess" json NOT NULL, "createdAt" TIMESTAMP NOT NULL, "updatedAt" TIMESTAMP NOT NULL, CONSTRAINT PK_${tablePrefix}814c3d3c36e8a27fa8edb761b0e PRIMARY KEY ("id"))`,
|
||||
undefined,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX IF NOT EXISTS IDX_${tablePrefix}07fde106c0b471d8cc80a64fc8 ON ${tablePrefix}credentials_entity (type) `,
|
||||
undefined,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE IF NOT EXISTS ${tablePrefix}execution_entity ("id" SERIAL NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" character varying NOT NULL, "retryOf" character varying, "retrySuccessId" character varying, "startedAt" TIMESTAMP NOT NULL, "stoppedAt" TIMESTAMP NOT NULL, "workflowData" json NOT NULL, "workflowId" character varying, CONSTRAINT PK_${tablePrefix}e3e63bbf986767844bbe1166d4e PRIMARY KEY ("id"))`,
|
||||
undefined,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX IF NOT EXISTS IDX_${tablePrefix}c4d999a5e90784e8caccf5589d ON ${tablePrefix}execution_entity ("workflowId") `,
|
||||
undefined,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE IF NOT EXISTS ${tablePrefix}workflow_entity ("id" SERIAL NOT NULL, "name" character varying(128) NOT NULL, "active" boolean NOT NULL, "nodes" json NOT NULL, "connections" json NOT NULL, "createdAt" TIMESTAMP NOT NULL, "updatedAt" TIMESTAMP NOT NULL, "settings" json, "staticData" json, CONSTRAINT PK_${tablePrefix}eded7d72664448da7745d551207 PRIMARY KEY ("id"))`,
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
let tablePrefix = getTablePrefix();
|
||||
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}workflow_entity`, undefined);
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}c4d999a5e90784e8caccf5589d`, undefined);
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}execution_entity`, undefined);
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}07fde106c0b471d8cc80a64fc8`, undefined);
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}credentials_entity`, undefined);
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}workflow_entity`);
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}c4d999a5e90784e8caccf5589d`);
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}execution_entity`);
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}07fde106c0b471d8cc80a64fc8`);
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}credentials_entity`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class WebhookModel1589476000887 implements MigrationInterface {
|
||||
name = 'WebhookModel1589476000887';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class WebhookModel1589476000887 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE IF NOT EXISTS ${tablePrefix}webhook_entity ("workflowId" integer NOT NULL, "webhookPath" character varying NOT NULL, "method" character varying NOT NULL, "node" character varying NOT NULL, CONSTRAINT "PK_${tablePrefix}b21ace2e13596ccd87dc9bf4ea6" PRIMARY KEY ("webhookPath", "method"))`,
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}webhook_entity`, undefined);
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}webhook_entity`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateIndexStoppedAt1594828256133 implements MigrationInterface {
|
||||
name = 'CreateIndexStoppedAt1594828256133';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class CreateIndexStoppedAt1594828256133 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX IF NOT EXISTS IDX_${tablePrefix}33228da131bb1112247cf52a42 ON ${tablePrefix}execution_entity ("stoppedAt") `,
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}33228da131bb1112247cf52a42`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, IrreversibleMigration } from '@db/types';
|
||||
|
||||
export class MakeStoppedAtNullable1607431743768 implements MigrationInterface {
|
||||
name = 'MakeStoppedAtNullable1607431743768';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class MakeStoppedAtNullable1607431743768 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE ' + tablePrefix + 'execution_entity ALTER COLUMN "stoppedAt" DROP NOT NULL',
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
// Cannot be undone as column might already have null values
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddWebhookId1611144599516 implements MigrationInterface {
|
||||
name = 'AddWebhookId1611144599516';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class AddWebhookId1611144599516 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}webhook_entity ADD "webhookId" character varying`,
|
||||
);
|
||||
@@ -15,8 +11,7 @@ export class AddWebhookId1611144599516 implements MigrationInterface {
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}16f4436789e804e3e1c9eeb240`);
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "pathLength"`);
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "webhookId"`);
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateTagEntity1617270242566 implements MigrationInterface {
|
||||
name = 'CreateTagEntity1617270242566';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateTagEntity1617270242566 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
// create tags table + relationship with workflow entity
|
||||
|
||||
await queryRunner.query(
|
||||
@@ -72,9 +67,7 @@ export class CreateTagEntity1617270242566 implements MigrationInterface {
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
// `createdAt` and `updatedAt`
|
||||
|
||||
await queryRunner.query(
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class UniqueWorkflowNames1620824779533 implements MigrationInterface {
|
||||
name = 'UniqueWorkflowNames1620824779533';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
const workflowNames = await queryRunner.query(`
|
||||
SELECT name
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
`);
|
||||
export class UniqueWorkflowNames1620824779533 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
const workflowNames = (await queryRunner.query(`
|
||||
SELECT name
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
`)) as Array<{ name: string }>;
|
||||
|
||||
for (const { name } of workflowNames) {
|
||||
const [duplicatesQuery, parameters] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
@@ -24,19 +19,22 @@ export class UniqueWorkflowNames1620824779533 implements MigrationInterface {
|
||||
{},
|
||||
);
|
||||
|
||||
const duplicates = await queryRunner.query(duplicatesQuery, parameters);
|
||||
const duplicates = (await queryRunner.query(duplicatesQuery, parameters)) as Array<{
|
||||
id: number;
|
||||
name: string;
|
||||
}>;
|
||||
|
||||
if (duplicates.length > 1) {
|
||||
await Promise.all(
|
||||
duplicates.map(({ id, name }: { id: number; name: string }, index: number) => {
|
||||
if (index === 0) return Promise.resolve();
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
duplicates.map(async ({ id, name }, index: number) => {
|
||||
if (index === 0) return;
|
||||
const [updateQuery, updateParams] =
|
||||
queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE ${tablePrefix}workflow_entity
|
||||
SET name = :name
|
||||
WHERE id = '${id}'
|
||||
`,
|
||||
`UPDATE ${tablePrefix}workflow_entity
|
||||
SET name = :name
|
||||
WHERE id = '${id}'
|
||||
`,
|
||||
{ name: `${name} ${index + 1}` },
|
||||
{},
|
||||
);
|
||||
@@ -52,8 +50,7 @@ export class UniqueWorkflowNames1620824779533 implements MigrationInterface {
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}a252c527c4c89237221fe2c0ab"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddwaitTill1626176912946 implements MigrationInterface {
|
||||
name = 'AddwaitTill1626176912946';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class AddwaitTill1626176912946 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}execution_entity ADD "waitTill" TIMESTAMP`);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX IF NOT EXISTS IDX_${tablePrefix}ca4a71b47f28ac6ea88293a8e2 ON ${tablePrefix}execution_entity ("waitTill")`,
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}ca4a71b47f28ac6ea88293a8e2`);
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "waitTill"`);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, runInBatches } from '@db/utils/migrationHelpers';
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import { runInBatches } from '@db/utils/migrationHelpers';
|
||||
|
||||
// replacing the credentials in workflows and execution
|
||||
// `nodeType: name` changes to `nodeType: { id, name }`
|
||||
|
||||
export class UpdateWorkflowCredentials1630419189837 implements MigrationInterface {
|
||||
name = 'UpdateWorkflowCredentials1630419189837';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
const credentialsEntities = await queryRunner.query(`
|
||||
export class UpdateWorkflowCredentials1630419189837 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
const credentialsEntities = (await queryRunner.query(`
|
||||
SELECT id, name, type
|
||||
FROM ${tablePrefix}credentials_entity
|
||||
`);
|
||||
`)) as Array<{ id: string; name: string; type: string }>;
|
||||
|
||||
const workflowsQuery = `
|
||||
SELECT id, nodes
|
||||
@@ -53,7 +55,7 @@ export class UpdateWorkflowCredentials1630419189837 implements MigrationInterfac
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -96,7 +98,7 @@ export class UpdateWorkflowCredentials1630419189837 implements MigrationInterfac
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -141,18 +143,16 @@ export class UpdateWorkflowCredentials1630419189837 implements MigrationInterfac
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
const credentialsEntities = await queryRunner.query(`
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
const credentialsEntities = (await queryRunner.query(`
|
||||
SELECT id, name, type
|
||||
FROM ${tablePrefix}credentials_entity
|
||||
`);
|
||||
`)) as Array<{ id: string; name: string; type: string }>;
|
||||
|
||||
const workflowsQuery = `
|
||||
SELECT id, nodes
|
||||
@@ -197,7 +197,7 @@ export class UpdateWorkflowCredentials1630419189837 implements MigrationInterfac
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -246,7 +246,7 @@ export class UpdateWorkflowCredentials1630419189837 implements MigrationInterfac
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -295,7 +295,7 @@ export class UpdateWorkflowCredentials1630419189837 implements MigrationInterfac
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class AddExecutionEntityIndexes1644422880309 implements MigrationInterface {
|
||||
name = 'AddExecutionEntityIndexes1644422880309';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddExecutionEntityIndexes1644422880309 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS IDX_${tablePrefix}c4d999a5e90784e8caccf5589d`);
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS IDX_${tablePrefix}ca4a71b47f28ac6ea88293a8e2`);
|
||||
await queryRunner.query(
|
||||
@@ -29,9 +24,7 @@ export class AddExecutionEntityIndexes1644422880309 implements MigrationInterfac
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}d160d4771aba5a0d78943edbe3"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}85b981df7b444f905f8bf50747"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}72ffaaab9f04c2c1f1ea86e662"`);
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, IrreversibleMigration } from '@db/types';
|
||||
|
||||
export class IncreaseTypeVarcharLimit1646834195327 implements MigrationInterface {
|
||||
name = 'IncreaseTypeVarcharLimit1646834195327';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class IncreaseTypeVarcharLimit1646834195327 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}credentials_entity ALTER COLUMN "type" TYPE VARCHAR(128)`,
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import type { InsertResult, MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { getTablePrefix, loadSurveyFromDisk } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateUserManagement1646992772331 implements MigrationInterface {
|
||||
name = 'CreateUserManagement1646992772331';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
import { loadSurveyFromDisk } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateUserManagement1646992772331 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}role (
|
||||
"id" serial NOT NULL,
|
||||
@@ -92,7 +88,9 @@ export class CreateUserManagement1646992772331 implements MigrationInterface {
|
||||
`INSERT INTO ${tablePrefix}role (name, scope) VALUES ('owner', 'global');`,
|
||||
);
|
||||
|
||||
const instanceOwnerRole = await queryRunner.query('SELECT lastval() as "insertId"');
|
||||
const instanceOwnerRole = (await queryRunner.query(
|
||||
'SELECT lastval() as "insertId"',
|
||||
)) as InsertResult;
|
||||
|
||||
await queryRunner.query(
|
||||
`INSERT INTO ${tablePrefix}role (name, scope) VALUES ('member', 'global');`,
|
||||
@@ -102,13 +100,17 @@ export class CreateUserManagement1646992772331 implements MigrationInterface {
|
||||
`INSERT INTO ${tablePrefix}role (name, scope) VALUES ('owner', 'workflow');`,
|
||||
);
|
||||
|
||||
const workflowOwnerRole = await queryRunner.query('SELECT lastval() as "insertId"');
|
||||
const workflowOwnerRole = (await queryRunner.query(
|
||||
'SELECT lastval() as "insertId"',
|
||||
)) as InsertResult;
|
||||
|
||||
await queryRunner.query(
|
||||
`INSERT INTO ${tablePrefix}role (name, scope) VALUES ('owner', 'credential');`,
|
||||
);
|
||||
|
||||
const credentialOwnerRole = await queryRunner.query('SELECT lastval() as "insertId"');
|
||||
const credentialOwnerRole = (await queryRunner.query(
|
||||
'SELECT lastval() as "insertId"',
|
||||
)) as InsertResult;
|
||||
|
||||
const survey = loadSurveyFromDisk();
|
||||
|
||||
@@ -133,9 +135,7 @@ export class CreateUserManagement1646992772331 implements MigrationInterface {
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_${tablePrefix}a252c527c4c89237221fe2c0ab" ON ${tablePrefix}workflow_entity ("name")`,
|
||||
);
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, IrreversibleMigration } from '@db/types';
|
||||
|
||||
export class LowerCaseUserEmail1648740597343 implements MigrationInterface {
|
||||
name = 'LowerCaseUserEmail1648740597343';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class LowerCaseUserEmail1648740597343 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`
|
||||
UPDATE "${tablePrefix}user"
|
||||
SET email = LOWER(email);
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CommunityNodes1652254514002 implements MigrationInterface {
|
||||
name = 'CommunityNodes1652254514002';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CommunityNodes1652254514002 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}installed_packages (` +
|
||||
'"packageName" VARCHAR(214) NOT NULL,' +
|
||||
@@ -31,11 +24,9 @@ export class CommunityNodes1652254514002 implements MigrationInterface {
|
||||
`CONSTRAINT "FK_${tablePrefix}73f857fc5dce682cef8a99c11dbddbc969618951" FOREIGN KEY ("package") REFERENCES ${tablePrefix}installed_packages ("packageName") ON DELETE CASCADE ON UPDATE CASCADE ` +
|
||||
');',
|
||||
);
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}installed_nodes"`);
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}installed_packages"`);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class AddUserSettings1652367743993 implements MigrationInterface {
|
||||
name = 'AddUserSettings1652367743993';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddUserSettings1652367743993 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE "${tablePrefix}user" ADD COLUMN settings json`);
|
||||
|
||||
await queryRunner.query(
|
||||
@@ -14,8 +9,7 @@ export class AddUserSettings1652367743993 implements MigrationInterface {
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE "${tablePrefix}user" DROP COLUMN settings`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddAPIKeyColumn1652905585850 implements MigrationInterface {
|
||||
name = 'AddAPIKeyColumn1652905585850';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class AddAPIKeyColumn1652905585850 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE "${tablePrefix}user" ADD COLUMN "apiKey" VARCHAR(255)`);
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "UQ_${tablePrefix}ie0zomxves9w3p774drfrkxtj5" ON "${tablePrefix}user" ("apiKey")`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP INDEX "UQ_${tablePrefix}ie0zomxves9w3p774drfrkxtj5"`);
|
||||
await queryRunner.query(`ALTER TABLE "${tablePrefix}user" DROP COLUMN "apiKey"`);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class IntroducePinData1654090467022 implements MigrationInterface {
|
||||
name = 'IntroducePinData1654090467022';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class IntroducePinData1654090467022 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity ADD "pinData" json`);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "pinData"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable n8n-local-rules/no-uncaught-json-parse */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { getTablePrefix, runInBatches } from '@db/utils/migrationHelpers';
|
||||
import { runInBatches } from '@db/utils/migrationHelpers';
|
||||
|
||||
// add node ids in workflow objects
|
||||
|
||||
export class AddNodeIds1658932090381 implements MigrationInterface {
|
||||
name = 'AddNodeIds1658932090381';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
export class AddNodeIds1658932090381 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
const workflowsQuery = `
|
||||
SELECT id, nodes
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
@@ -36,14 +37,12 @@ export class AddNodeIds1658932090381 implements MigrationInterface {
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
const workflowsQuery = `
|
||||
SELECT id, nodes
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
@@ -57,16 +56,14 @@ export class AddNodeIds1658932090381 implements MigrationInterface {
|
||||
nodes.forEach((node) => delete node.id);
|
||||
|
||||
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE ${tablePrefix}workflow_entity
|
||||
SET nodes = :nodes
|
||||
WHERE id = '${workflow.id}'
|
||||
`,
|
||||
`UPDATE ${tablePrefix}workflow_entity
|
||||
SET nodes = :nodes
|
||||
WHERE id = '${workflow.id}'`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
import {
|
||||
getTablePrefix,
|
||||
logMigrationEnd,
|
||||
logMigrationStart,
|
||||
runInBatches,
|
||||
} from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, IrreversibleMigration } from '@/databases/types';
|
||||
import { runInBatches } from '@db/utils/migrationHelpers';
|
||||
import { addJsonKeyToPinDataColumn } from '../sqlite/1659888469333-AddJsonKeyPinData';
|
||||
import type { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Convert JSON-type `pinData` column in `workflow_entity` table from
|
||||
* `{ [nodeName: string]: IDataObject[] }` to `{ [nodeName: string]: INodeExecutionData[] }`
|
||||
*/
|
||||
export class AddJsonKeyPinData1659902242948 implements MigrationInterface {
|
||||
name = 'AddJsonKeyPinData1659902242948';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const workflowTable = `${getTablePrefix()}workflow_entity`;
|
||||
export class AddJsonKeyPinData1659902242948 implements IrreversibleMigration {
|
||||
async up(context: MigrationContext) {
|
||||
const { queryRunner, tablePrefix } = context;
|
||||
const workflowTable = `${tablePrefix}workflow_entity`;
|
||||
|
||||
const PINDATA_SELECT_QUERY = `
|
||||
SELECT id, "pinData"
|
||||
@@ -34,13 +26,7 @@ export class AddJsonKeyPinData1659902242948 implements MigrationInterface {
|
||||
await runInBatches(
|
||||
queryRunner,
|
||||
PINDATA_SELECT_QUERY,
|
||||
addJsonKeyToPinDataColumn(queryRunner, PINDATA_UPDATE_STATEMENT),
|
||||
addJsonKeyToPinDataColumn(context, PINDATA_UPDATE_STATEMENT),
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down() {
|
||||
// irreversible migration
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateCredentialsUserRole1660062385367 implements MigrationInterface {
|
||||
name = 'CreateCredentialsUserRole1660062385367';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class CreateCredentialsUserRole1660062385367 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`
|
||||
INSERT INTO ${tablePrefix}role (name, scope)
|
||||
VALUES ('user', 'credential')
|
||||
@@ -13,8 +9,7 @@ export class CreateCredentialsUserRole1660062385367 implements MigrationInterfac
|
||||
`);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`
|
||||
DELETE FROM ${tablePrefix}role WHERE name='user' AND scope='credential';
|
||||
`);
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateWorkflowsEditorRole1663755770893 implements MigrationInterface {
|
||||
name = 'CreateWorkflowsEditorRole1663755770893';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateWorkflowsEditorRole1663755770893 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`
|
||||
INSERT INTO ${tablePrefix}role (name, scope)
|
||||
VALUES ('editor', 'workflow')
|
||||
ON CONFLICT DO NOTHING;
|
||||
`);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`
|
||||
DELETE FROM ${tablePrefix}role WHERE name='user' AND scope='workflow';
|
||||
`);
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class WorkflowStatistics1664196174001 implements MigrationInterface {
|
||||
name = 'WorkflowStatistics1664196174001';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class WorkflowStatistics1664196174001 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
// Create statistics table
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}workflow_statistics (
|
||||
@@ -24,12 +18,9 @@ export class WorkflowStatistics1664196174001 implements MigrationInterface {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}workflow_entity ADD COLUMN "dataLoaded" BOOLEAN DEFAULT false;`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}workflow_statistics`);
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN dataLoaded`);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateCredentialUsageTable1665484192212 implements MigrationInterface {
|
||||
name = 'CreateCredentialUsageTable1665484192212';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateCredentialUsageTable1665484192212 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}credential_usage (` +
|
||||
'"workflowId" int NOT NULL,' +
|
||||
@@ -20,13 +14,9 @@ export class CreateCredentialUsageTable1665484192212 implements MigrationInterfa
|
||||
`CONSTRAINT "FK_${tablePrefix}7ce200a20ade7ae89fa7901da896993f" FOREIGN KEY ("credentialId") REFERENCES ${tablePrefix}credentials_entity ("id") ON DELETE CASCADE ON UPDATE CASCADE ` +
|
||||
');',
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}credential_usage"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class RemoveCredentialUsageTable1665754637025 implements MigrationInterface {
|
||||
name = 'RemoveCredentialUsageTable1665754637025';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class RemoveCredentialUsageTable1665754637025 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}credential_usage`);
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}credential_usage (` +
|
||||
'"workflowId" int NOT NULL,' +
|
||||
|
||||
@@ -1,42 +1,31 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class AddWorkflowVersionIdColumn1669739707126 implements MigrationInterface {
|
||||
name = 'AddWorkflowVersionIdColumn1669739707126';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
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: Array<{ id: number }> = await queryRunner.query(`
|
||||
const workflowIds = (await queryRunner.query(`
|
||||
SELECT id
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
`);
|
||||
`)) as Array<{ id: number }>;
|
||||
|
||||
workflowIds.map(({ id }) => {
|
||||
for (const { id } of workflowIds) {
|
||||
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE ${tablePrefix}workflow_entity
|
||||
SET "versionId" = :versionId
|
||||
WHERE id = '${id}'
|
||||
`,
|
||||
`UPDATE ${tablePrefix}workflow_entity
|
||||
SET "versionId" = :versionId
|
||||
WHERE id = '${id}'`,
|
||||
{ versionId: uuidv4() },
|
||||
{},
|
||||
);
|
||||
|
||||
return queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
}
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "versionId"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class AddTriggerCountColumn1669823906995 implements MigrationInterface {
|
||||
name = 'AddTriggerCountColumn1669823906995';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddTriggerCountColumn1669823906995 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}workflow_entity ADD COLUMN "triggerCount" integer NOT NULL DEFAULT 0`,
|
||||
);
|
||||
// Table will be populated by n8n startup - see ActiveWorkflowRunner.ts
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "triggerCount"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class MessageEventBusDestinations1671535397530 implements MigrationInterface {
|
||||
name = 'MessageEventBusDestinations1671535397530';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
export class MessageEventBusDestinations1671535397530 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}event_destinations (` +
|
||||
`"id" UUID PRIMARY KEY NOT NULL,` +
|
||||
`"destination" JSONB NOT NULL,` +
|
||||
`"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,` +
|
||||
`"updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);`,
|
||||
'"id" UUID PRIMARY KEY NOT NULL,' +
|
||||
'"destination" JSONB NOT NULL,' +
|
||||
'"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
|
||||
'"updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);',
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}event_destinations"`);
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import { StatisticsNames } from '@db/entities/WorkflowStatistics';
|
||||
|
||||
export class RemoveWorkflowDataLoadedFlag1671726148421 implements MigrationInterface {
|
||||
name = 'RemoveWorkflowDataLoadedFlag1671726148421';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import { StatisticsNames } from '@/databases/entities/WorkflowStatistics';
|
||||
|
||||
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: Array<{ id: number; dataLoaded: boolean }> = await queryRunner.query(`
|
||||
const workflowIds = (await queryRunner.query(`
|
||||
SELECT id, "dataLoaded"
|
||||
FROM ${tablePrefix}workflow_entity
|
||||
`);
|
||||
`)) as Array<{ id: number; dataLoaded: boolean }>;
|
||||
|
||||
workflowIds.map(({ id, dataLoaded }) => {
|
||||
workflowIds.map(async ({ id, dataLoaded }) => {
|
||||
if (dataLoaded) {
|
||||
const [insertQuery, insertParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
@@ -32,24 +26,20 @@ export class RemoveWorkflowDataLoadedFlag1671726148421 implements MigrationInter
|
||||
});
|
||||
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflow_entity DROP COLUMN "dataLoaded"`);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
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: Array<{ workflowId: string }> = await queryRunner.query(`
|
||||
const workflowsIds = (await queryRunner.query(`
|
||||
SELECT "workflowId"
|
||||
FROM ${tablePrefix}workflow_statistics
|
||||
WHERE name = '${StatisticsNames.dataLoaded}'
|
||||
`);
|
||||
workflowsIds.map(({ workflowId }) => {
|
||||
`)) as Array<{ workflowId: string }>;
|
||||
workflowsIds.map(async ({ workflowId }) => {
|
||||
return queryRunner.query(`
|
||||
UPDATE ${tablePrefix}workflow_entity
|
||||
SET "dataLoaded" = true
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class DeleteExecutionsWithWorkflows1673268682475 implements MigrationInterface {
|
||||
name = 'DeleteExecutionsWithWorkflows1673268682475';
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class DeleteExecutionsWithWorkflows1673268682475 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}execution_entity
|
||||
ALTER COLUMN "workflowId" TYPE INTEGER USING "workflowId"::integer`,
|
||||
);
|
||||
|
||||
const workflowIds: Array<{ id: number }> = await queryRunner.query(`
|
||||
const workflowIds = (await queryRunner.query(`
|
||||
SELECT id FROM ${tablePrefix}workflow_entity
|
||||
`);
|
||||
`)) as Array<{ id: number }>;
|
||||
|
||||
await queryRunner.query(
|
||||
`DELETE FROM ${tablePrefix}execution_entity
|
||||
@@ -32,12 +27,9 @@ export class DeleteExecutionsWithWorkflows1673268682475 implements MigrationInte
|
||||
FOREIGN KEY ("workflowId") REFERENCES ${tablePrefix}workflow_entity ("id")
|
||||
ON DELETE CASCADE`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE ${tablePrefix}execution_entity
|
||||
DROP CONSTRAINT "FK_${tablePrefix}execution_entity_workflowId"`,
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import config from '@/config';
|
||||
|
||||
export class AddStatusToExecutions1674138566000 implements MigrationInterface {
|
||||
name = 'AddStatusToExecutions1674138566000';
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class AddStatusToExecutions1674138566000 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}execution_entity ADD COLUMN status varchar`);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}execution_entity DROP COLUMN status`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import { LDAP_DEFAULT_CONFIGURATION, LDAP_FEATURE_NAME } from '@/Ldap/constants';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateLdapEntities1674509946020 implements MigrationInterface {
|
||||
name = 'CreateLdapEntities1674509946020';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
export class CreateLdapEntities1674509946020 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "${tablePrefix}user" ADD COLUMN disabled BOOLEAN NOT NULL DEFAULT false;`,
|
||||
);
|
||||
@@ -45,12 +38,9 @@ export class CreateLdapEntities1674509946020 implements MigrationInterface {
|
||||
"error" TEXT
|
||||
);`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}auth_provider_sync_history"`);
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}auth_identity"`);
|
||||
|
||||
|
||||
@@ -1,28 +1,19 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import type { IConnections, INode } from 'n8n-workflow';
|
||||
import type { MigrationContext, IrreversibleMigration } from '@db/types';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { IConnections, INode } from 'n8n-workflow';
|
||||
import { getLogger } from '@/Logger';
|
||||
import { Container } from 'typedi';
|
||||
export class PurgeInvalidWorkflowConnections1675940580449 implements MigrationInterface {
|
||||
name = 'PurgeInvalidWorkflowConnections1675940580449';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
const workflows: Array<{ id: number; nodes: INode[]; connections: IConnections }> =
|
||||
await queryRunner.query(`
|
||||
export class PurgeInvalidWorkflowConnections1675940580449 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix, migrationName, logger }: MigrationContext) {
|
||||
const workflows = (await queryRunner.query(`
|
||||
SELECT id, nodes, connections
|
||||
FROM "${tablePrefix}workflow_entity"
|
||||
`);
|
||||
`)) as Array<{ id: number; nodes: INode[]; connections: IConnections }>;
|
||||
|
||||
const nodeTypes = Container.get(NodeTypes);
|
||||
|
||||
workflows.forEach(async (workflow) => {
|
||||
let connections: IConnections = workflow.connections;
|
||||
const nodes: INode[] = workflow.nodes;
|
||||
const { connections, nodes } = workflow;
|
||||
|
||||
const nodesThatCannotReceiveInput: string[] = nodes.reduce((acc, node) => {
|
||||
try {
|
||||
@@ -31,7 +22,7 @@ export class PurgeInvalidWorkflowConnections1675940580449 implements MigrationIn
|
||||
acc.push(node.name);
|
||||
}
|
||||
} catch (error) {
|
||||
getLogger().warn(`Migration ${this.name} failed with error: ${error.message}`);
|
||||
logger.warn(`Migration ${migrationName} failed with error: ${(error as Error).message}`);
|
||||
}
|
||||
return acc;
|
||||
}, [] as string[]);
|
||||
@@ -40,7 +31,7 @@ export class PurgeInvalidWorkflowConnections1675940580449 implements MigrationIn
|
||||
const connection = connections[sourceNodeName];
|
||||
const outputs = Object.keys(connection);
|
||||
|
||||
outputs.forEach((outputConnectionName /* Like `main` */, idx) => {
|
||||
outputs.forEach((outputConnectionName /* Like `main` */) => {
|
||||
const outputConnection = connection[outputConnectionName];
|
||||
|
||||
// It filters out all connections that are connected to a node that cannot receive input
|
||||
@@ -55,22 +46,14 @@ export class PurgeInvalidWorkflowConnections1675940580449 implements MigrationIn
|
||||
|
||||
// Update database with new connections
|
||||
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE "${tablePrefix}workflow_entity"
|
||||
SET connections = :connections
|
||||
WHERE id = '${workflow.id}'
|
||||
`,
|
||||
`UPDATE "${tablePrefix}workflow_entity"
|
||||
SET connections = :connections
|
||||
WHERE id = '${workflow.id}'`,
|
||||
{ connections: JSON.stringify(connections) },
|
||||
{},
|
||||
);
|
||||
|
||||
await queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
// No need to revert this migration
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import config from '@/config';
|
||||
|
||||
export class MigrateExecutionStatus1676996103000 implements MigrationInterface {
|
||||
name = 'MigrateExecutionStatus1676996103000';
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
import type { MigrationContext, IrreversibleMigration } from '@db/types';
|
||||
|
||||
export class MigrateExecutionStatus1676996103000 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`UPDATE "${tablePrefix}execution_entity" SET "status" = 'waiting' WHERE "status" IS NULL AND "waitTill" IS NOT NULL;`,
|
||||
);
|
||||
@@ -20,9 +14,5 @@ export class MigrateExecutionStatus1676996103000 implements MigrationInterface {
|
||||
await queryRunner.query(
|
||||
`UPDATE "${tablePrefix}execution_entity" SET "status" = 'crashed' WHERE "status" IS NULL;`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import config from '@/config';
|
||||
|
||||
export class UpdateRunningExecutionStatus1677236854063 implements MigrationInterface {
|
||||
name = 'UpdateRunningExecutionStatus1677236854063';
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
import type { MigrationContext, IrreversibleMigration } from '@db/types';
|
||||
|
||||
export class UpdateRunningExecutionStatus1677236854063 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`UPDATE "${tablePrefix}execution_entity" SET "status" = 'failed' WHERE "status" = 'running' AND "finished"=false AND "stoppedAt" IS NOT NULL;`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`UPDATE "${tablePrefix}execution_entity" SET "status" = 'success' WHERE "status" = 'running' AND "finished"=true AND "stoppedAt" IS NOT NULL;`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { logMigrationEnd, logMigrationStart, getTablePrefix } from '@db/utils/migrationHelpers';
|
||||
import config from '@/config';
|
||||
|
||||
export class CreateVariables1677501636754 implements MigrationInterface {
|
||||
name = 'CreateVariables1677501636754';
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateVariables1677501636754 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE ${tablePrefix}variables (
|
||||
id serial4 NOT NULL PRIMARY KEY,
|
||||
@@ -17,16 +11,9 @@ export class CreateVariables1677501636754 implements MigrationInterface {
|
||||
UNIQUE ("key")
|
||||
);
|
||||
`);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(`DROP TABLE ${tablePrefix}variables;`);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
|
||||
export class CreateExecutionMetadataTable1679416281778 implements MigrationInterface {
|
||||
name = 'CreateExecutionMetadataTable1679416281778';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = getTablePrefix();
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class CreateExecutionMetadataTable1679416281778 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE ${tablePrefix}execution_metadata (
|
||||
"id" serial4 NOT NULL PRIMARY KEY,
|
||||
@@ -32,13 +26,9 @@ export class CreateExecutionMetadataTable1679416281778 implements MigrationInter
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_${tablePrefix}8b6f3f9ae234f137d707b98f3bf43584" ON "${tablePrefix}execution_entity" ("status", "workflowId");`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
// Re-add removed indices
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX IF NOT EXISTS "IDX_${tablePrefix}33228da131bb1112247cf52a42" ON ${tablePrefix}execution_entity ("stoppedAt") `,
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { getTablePrefix, logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
import type { UserSettings } from '@/Interfaces';
|
||||
|
||||
export class AddUserActivatedProperty1681134145996 implements MigrationInterface {
|
||||
name = 'AddUserActivatedProperty1681134145996';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const tablePrefix = getTablePrefix();
|
||||
|
||||
const activatedUsers: UserSettings[] = await queryRunner.query(
|
||||
export class AddUserActivatedProperty1681134145996 implements ReversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
const activatedUsers = (await queryRunner.query(
|
||||
`SELECT DISTINCT sw."userId" AS id,
|
||||
JSONB_SET(COALESCE(u.settings::jsonb, '{}'), '{userActivated}', 'true', true) as settings
|
||||
FROM ${tablePrefix}workflow_statistics ws
|
||||
@@ -23,9 +16,9 @@ export class AddUserActivatedProperty1681134145996 implements MigrationInterface
|
||||
WHERE ws.name = 'production_success'
|
||||
AND r.name = 'owner'
|
||||
AND r.scope = 'workflow'`,
|
||||
);
|
||||
)) as UserSettings[];
|
||||
|
||||
const updatedUsers = activatedUsers.map((user) =>
|
||||
const updatedUsers = activatedUsers.map(async (user) =>
|
||||
queryRunner.query(
|
||||
`UPDATE "${tablePrefix}user" SET settings = '${JSON.stringify(
|
||||
user.settings,
|
||||
@@ -46,12 +39,9 @@ export class AddUserActivatedProperty1681134145996 implements MigrationInterface
|
||||
`UPDATE "${tablePrefix}user" SET settings = JSONB_SET(COALESCE(settings::jsonb, '{}'), '{userActivated}', 'false', true) WHERE id NOT IN (${activatedUserIds})`,
|
||||
);
|
||||
}
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = getTablePrefix();
|
||||
async down({ queryRunner, tablePrefix }: MigrationContext) {
|
||||
await queryRunner.query(
|
||||
`UPDATE "${tablePrefix}user" SET settings = settings::jsonb - 'userActivated'`,
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Migration } from '@db/types';
|
||||
import { InitialMigration1587669153312 } from './1587669153312-InitialMigration';
|
||||
import { WebhookModel1589476000887 } from './1589476000887-WebhookModel';
|
||||
import { CreateIndexStoppedAt1594828256133 } from './1594828256133-CreateIndexStoppedAt';
|
||||
@@ -36,7 +37,7 @@ import { CreateExecutionMetadataTable1679416281778 } from './1679416281778-Creat
|
||||
import { CreateVariables1677501636754 } from './1677501636754-CreateVariables';
|
||||
import { AddUserActivatedProperty1681134145996 } from './1681134145996-AddUserActivatedProperty';
|
||||
|
||||
export const postgresMigrations = [
|
||||
export const postgresMigrations: Migration[] = [
|
||||
InitialMigration1587669153312,
|
||||
WebhookModel1589476000887,
|
||||
CreateIndexStoppedAt1594828256133,
|
||||
|
||||
Reference in New Issue
Block a user