mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
🚧 🐘 postgres migration
This commit is contained in:
parent
d91b0f52cb
commit
575d9fb758
|
@ -32,11 +32,7 @@ export let collections: IDatabaseCollections = {
|
|||
Webhook: null,
|
||||
};
|
||||
|
||||
import {
|
||||
CreateIndexStoppedAt1594828256133,
|
||||
InitialMigration1587669153312,
|
||||
WebhookModel1589476000887,
|
||||
} from './databases/postgresdb/migrations';
|
||||
import postgresMigrations from './databases/postgresdb/migrations';
|
||||
|
||||
import {
|
||||
CreateIndexStoppedAt1594910478695,
|
||||
|
@ -50,11 +46,7 @@ import {
|
|||
WebhookModel1592447867632,
|
||||
} from './databases/mysqldb/migrations';
|
||||
|
||||
import {
|
||||
CreateIndexStoppedAt1594825041918,
|
||||
InitialMigration1588102412422,
|
||||
WebhookModel1592445003908,
|
||||
} from './databases/sqlite/migrations';
|
||||
import sqliteMigrations from './databases/sqlite/migrations';
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
|
@ -112,11 +104,7 @@ export async function init(): Promise<IDatabaseCollections> {
|
|||
port: await GenericHelpers.getConfigValue('database.postgresdb.port') as number,
|
||||
username: await GenericHelpers.getConfigValue('database.postgresdb.user') as string,
|
||||
schema: config.get('database.postgresdb.schema'),
|
||||
migrations: [
|
||||
InitialMigration1587669153312,
|
||||
WebhookModel1589476000887,
|
||||
CreateIndexStoppedAt1594828256133,
|
||||
],
|
||||
migrations: postgresMigrations,
|
||||
migrationsRun: true,
|
||||
migrationsTableName: `${entityPrefix}migrations`,
|
||||
ssl,
|
||||
|
@ -151,11 +139,7 @@ export async function init(): Promise<IDatabaseCollections> {
|
|||
type: 'sqlite',
|
||||
database: path.join(n8nFolder, 'database.sqlite'),
|
||||
entityPrefix,
|
||||
migrations: [
|
||||
InitialMigration1588102412422,
|
||||
WebhookModel1592445003908,
|
||||
CreateIndexStoppedAt1594825041918,
|
||||
],
|
||||
migrations: sqliteMigrations,
|
||||
migrationsRun: true,
|
||||
migrationsTableName: `${entityPrefix}migrations`,
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ import {
|
|||
Column,
|
||||
Entity,
|
||||
PrimaryColumn,
|
||||
Index,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
|
@ -9,6 +10,7 @@ import {
|
|||
} from '../../';
|
||||
|
||||
@Entity()
|
||||
@Index(["webhookId", "method"], { unique: true })
|
||||
export class WebhookEntity implements IWebhookDb {
|
||||
|
||||
@Column()
|
||||
|
@ -22,4 +24,7 @@ export class WebhookEntity implements IWebhookDb {
|
|||
|
||||
@Column()
|
||||
node: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
webhookId: string;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
|
||||
import * as config from '../../../../config';
|
||||
|
||||
export class InitialMigration1587669153312 implements MigrationInterface {
|
||||
export default class InitialMigration1587669153312 implements MigrationInterface {
|
||||
name = 'InitialMigration1587669153312';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
|
||||
import * as config from '../../../../config';
|
||||
|
||||
export class WebhookModel1589476000887 implements MigrationInterface {
|
||||
export default class WebhookModel1589476000887 implements MigrationInterface {
|
||||
name = 'WebhookModel1589476000887';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm";
|
|||
|
||||
import * as config from '../../../../config';
|
||||
|
||||
export class CreateIndexStoppedAt1594828256133 implements MigrationInterface {
|
||||
export default class CreateIndexStoppedAt1594828256133 implements MigrationInterface {
|
||||
name = 'CreateIndexStoppedAt1594828256133';
|
||||
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
import * as config from '../../../../config';
|
||||
|
||||
export default class AddWebhookId1610632462428 implements MigrationInterface {
|
||||
name = 'AddWebhookId1610632462428';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
let tablePrefix = config.get('database.tablePrefix');
|
||||
const tablePrefixPure = tablePrefix;
|
||||
const schema = config.get('database.postgresdb.schema');
|
||||
if (schema) {
|
||||
tablePrefix = schema + '.' + tablePrefix;
|
||||
}
|
||||
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity ADD "webhookId" character varying`);
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_${tablePrefixPure}5c698bcd4092bc271cabdf7814" ON ${tablePrefix}webhook_entity ("webhookId", "method") `,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
let tablePrefix = config.get('database.tablePrefix');
|
||||
const tablePrefixPure = tablePrefix;
|
||||
const schema = config.get('database.postgresdb.schema');
|
||||
if (schema) {
|
||||
tablePrefix = schema + '.' + tablePrefix;
|
||||
}
|
||||
|
||||
await queryRunner.query(`DROP INDEX IDX_${tablePrefixPure}5c698bcd4092bc271cabdf7814`);
|
||||
await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "webhookId"`);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,11 @@
|
|||
export * from './1587669153312-InitialMigration';
|
||||
export * from './1589476000887-WebhookModel';
|
||||
export * from './1594828256133-CreateIndexStoppedAt';
|
||||
import InitialMigration1587669153312 from './1587669153312-InitialMigration';
|
||||
import WebhookModel1589476000887 from './1589476000887-WebhookModel';
|
||||
import CreateIndexStoppedAt1594828256133 from './1594828256133-CreateIndexStoppedAt';
|
||||
import AddWebhookId1610632462428 from './1610632462428-AddWebhookId'
|
||||
|
||||
export default [
|
||||
InitialMigration1587669153312,
|
||||
WebhookModel1589476000887,
|
||||
CreateIndexStoppedAt1594828256133,
|
||||
AddWebhookId1610632462428,
|
||||
]
|
||||
|
|
|
@ -1,28 +1,37 @@
|
|||
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
import * as config from '../../../../config';
|
||||
|
||||
export default class AddWebhookId1610570498276 implements MigrationInterface {
|
||||
name = 'AddWebhookId1610570498276'
|
||||
name = 'AddWebhookId1610570498276';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = config.get('database.tablePrefix');
|
||||
|
||||
await queryRunner.query(`CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))`);
|
||||
await queryRunner.query(`INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`);
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") `);
|
||||
}
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`,
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`);
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") `,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = config.get('database.tablePrefix');
|
||||
|
||||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004"`);
|
||||
await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`);
|
||||
await queryRunner.query(`CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`);
|
||||
await queryRunner.query(`INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`);
|
||||
await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`);
|
||||
}
|
||||
|
||||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004"`);
|
||||
await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`,
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue