n8n/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts

37 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-05-13 00:22:14 -07:00
import { MigrationInterface, QueryRunner } from 'typeorm';
import * as config from '../../../../config';
2020-04-27 03:46:09 -07:00
export class InitialMigration1587669153312 implements MigrationInterface {
2020-05-04 08:29:39 -07:00
name = 'InitialMigration1587669153312';
2020-04-27 03:46:09 -07:00
2020-05-04 08:29:39 -07:00
async up(queryRunner: QueryRunner): Promise<void> {
2020-05-13 00:31:31 -07:00
let tablePrefix = config.get('database.tablePrefix');
const schema = config.get('database.postgresdb.schema');
if (schema) {
tablePrefix = schema + '.' + tablePrefix;
}
2020-05-13 00:22:14 -07:00
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_814c3d3c36e8a27fa8edb761b0e PRIMARY KEY ("id"))`, undefined);
await queryRunner.query(`CREATE INDEX IF NOT EXISTS IDX_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_e3e63bbf986767844bbe1166d4e PRIMARY KEY ("id"))`, undefined);
await queryRunner.query(`CREATE INDEX IF NOT EXISTS IDX_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_eded7d72664448da7745d551207 PRIMARY KEY ("id"))`, undefined);
2020-05-04 08:29:39 -07:00
}
2020-04-27 03:46:09 -07:00
2020-05-04 08:29:39 -07:00
async down(queryRunner: QueryRunner): Promise<void> {
2020-05-13 00:31:31 -07:00
let tablePrefix = config.get('database.tablePrefix');
const schema = config.get('database.postgresdb.schema');
if (schema) {
tablePrefix = schema + '.' + tablePrefix;
}
2020-05-13 00:22:14 -07:00
await queryRunner.query(`DROP TABLE ${tablePrefix}workflow_entity`, undefined);
2020-05-04 08:29:39 -07:00
await queryRunner.query(`DROP INDEX IDX_c4d999a5e90784e8caccf5589d`, undefined);
2020-05-13 00:22:14 -07:00
await queryRunner.query(`DROP TABLE ${tablePrefix}execution_entity`, undefined);
2020-05-04 08:29:39 -07:00
await queryRunner.query(`DROP INDEX IDX_07fde106c0b471d8cc80a64fc8`, undefined);
2020-05-13 00:22:14 -07:00
await queryRunner.query(`DROP TABLE ${tablePrefix}credentials_entity`, undefined);
2020-05-04 08:29:39 -07:00
}
2020-04-27 03:46:09 -07:00
}