Skip to content

Commit

Permalink
fix postgres migrations when custom schema is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
olimsaidov committed May 27, 2022
1 parent c38f6af commit b645385
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class InitialMigration1587669153312 implements MigrationInterface {
}

await queryRunner.query(`DROP TABLE ${tablePrefix}workflow_entity`, undefined);
await queryRunner.query(`DROP INDEX IDX_${tablePrefixIndex}c4d999a5e90784e8caccf5589d`, undefined);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixIndex}c4d999a5e90784e8caccf5589d`, undefined);
await queryRunner.query(`DROP TABLE ${tablePrefix}execution_entity`, undefined);
await queryRunner.query(`DROP INDEX IDX_${tablePrefixIndex}07fde106c0b471d8cc80a64fc8`, undefined);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixIndex}07fde106c0b471d8cc80a64fc8`, undefined);
await queryRunner.query(`DROP TABLE ${tablePrefix}credentials_entity`, undefined);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class CreateIndexStoppedAt1594828256133 implements MigrationInterface {
}

async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.getEnv('database.tablePrefix');
const tablePrefixPure = config.getEnv('database.tablePrefix');

await queryRunner.query(`DROP INDEX IDX_${tablePrefix}33228da131bb1112247cf52a42`);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixPure}33228da131bb1112247cf52a42`);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AddWebhookId1611144599516 implements MigrationInterface {
tablePrefix = schema + '.' + tablePrefix;
}

await queryRunner.query(`DROP INDEX IDX_${tablePrefixPure}16f4436789e804e3e1c9eeb240`);
await queryRunner.query(`DROP "${schema}".INDEX IDX_${tablePrefixPure}16f4436789e804e3e1c9eeb240`);
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "pathLength"`);
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "webhookId"`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export class CreateTagEntity1617270242566 implements MigrationInterface {

await queryRunner.query(`ALTER TABLE ${tablePrefix}workflows_tags DROP CONSTRAINT "FK_${tablePrefixPure}5e29bfe9e22c5d6567f509d4a46"`);
await queryRunner.query(`ALTER TABLE ${tablePrefix}workflows_tags DROP CONSTRAINT "FK_${tablePrefixPure}31140eb41f019805b40d0087449"`);
await queryRunner.query(`DROP INDEX IDX_${tablePrefixPure}5e29bfe9e22c5d6567f509d4a4`);
await queryRunner.query(`DROP INDEX IDX_${tablePrefixPure}31140eb41f019805b40d008744`);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixPure}5e29bfe9e22c5d6567f509d4a4`);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixPure}31140eb41f019805b40d008744`);
await queryRunner.query(`DROP TABLE ${tablePrefix}workflows_tags`);
await queryRunner.query(`DROP INDEX IDX_${tablePrefixPure}812eb05f7451ca757fb98444ce`);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixPure}812eb05f7451ca757fb98444ce`);
await queryRunner.query(`DROP TABLE ${tablePrefix}tag_entity`);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ export class UniqueWorkflowNames1620824779533 implements MigrationInterface {
tablePrefix = schema + '.' + tablePrefix;
}

await queryRunner.query(`DROP INDEX "IDX_${tablePrefixPure}a252c527c4c89237221fe2c0ab"`);
await queryRunner.query(`DROP INDEX "${schema}"."IDX_${tablePrefixPure}a252c527c4c89237221fe2c0ab"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AddwaitTill1626176912946 implements MigrationInterface {
tablePrefix = schema + '.' + tablePrefix;
}

await queryRunner.query(`DROP INDEX IDX_${tablePrefixPure}ca4a71b47f28ac6ea88293a8e2`);
await queryRunner.query(`DROP INDEX "${schema}".IDX_${tablePrefixPure}ca4a71b47f28ac6ea88293a8e2`);
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "waitTill"`);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export class IncreaseTypeVarcharLimit1646834195327 implements MigrationInterface
name = 'IncreaseTypeVarcharLimit1646834195327';

async up(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.getEnv('database.tablePrefix');
let tablePrefix = config.getEnv('database.tablePrefix');
const tablePrefixPure = tablePrefix;
const schema = config.getEnv('database.postgresdb.schema');
if (schema) {
tablePrefix = schema + '.' + tablePrefix;
}
await queryRunner.query(`ALTER TABLE ${tablePrefix}credentials_entity ALTER COLUMN "type" TYPE VARCHAR(128)`);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class CreateUserManagement1646992772331 implements MigrationInterface {
CONSTRAINT "FK_${tablePrefixPure}3540da03964527aa24ae014b780" FOREIGN KEY ("roleId") REFERENCES ${tablePrefix}role ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT "FK_${tablePrefixPure}82b2fd9ec4e3e24209af8160282" FOREIGN KEY ("userId") REFERENCES ${tablePrefix}user ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "FK_${tablePrefixPure}b83f8d2530884b66a9c848c8b88" FOREIGN KEY ("workflowId") REFERENCES
${tablePrefixPure}workflow_entity ("id") ON DELETE CASCADE ON UPDATE NO ACTION
${tablePrefix}workflow_entity ("id") ON DELETE CASCADE ON UPDATE NO ACTION
);`,
);

await queryRunner.query(
`CREATE INDEX "IDX_${tablePrefixPure}65a0933c0f19d278881653bf81d35064" ON "shared_workflow" ("workflowId");`,
`CREATE INDEX "IDX_${tablePrefixPure}65a0933c0f19d278881653bf81d35064" ON ${tablePrefix}"shared_workflow" ("workflowId");`,
);

await queryRunner.query(
Expand Down Expand Up @@ -91,7 +91,7 @@ export class CreateUserManagement1646992772331 implements MigrationInterface {
);`,
);

await queryRunner.query(`DROP INDEX "IDX_${tablePrefixPure}a252c527c4c89237221fe2c0ab"`);
await queryRunner.query(`DROP INDEX "${schema}"."IDX_${tablePrefixPure}a252c527c4c89237221fe2c0ab"`);

// Insert initial roles
await queryRunner.query(
Expand Down

0 comments on commit b645385

Please sign in to comment.