🚧 add mySQL migration

This commit is contained in:
Ben Hesseldieck 2021-01-14 17:26:56 +01:00
parent 575d9fb758
commit 3419d4b69f
8 changed files with 47 additions and 30 deletions

View file

@ -110,7 +110,7 @@ By default n8n uses SQLite to save credentials, past executions and workflows.
n8n however also supports MongoDB and PostgresDB. To use them simply a few
environment variables have to be set.
It is important to still persist the data in the `/root/.n8` folder. The reason
It is important to still persist the data in the `/root/.n8n` folder. The reason
is that it contains n8n user data. That is the name of the webhook
(in case) the n8n tunnel gets used and even more important the encryption key
for the credentials. If none gets found n8n creates automatically one on

View file

@ -33,19 +33,8 @@ export let collections: IDatabaseCollections = {
};
import postgresMigrations from './databases/postgresdb/migrations';
import {
CreateIndexStoppedAt1594910478695,
InitialMigration1587563438936,
WebhookModel1592679094242,
} from './databases/mongodb/migrations';
import {
CreateIndexStoppedAt1594902918301,
InitialMigration1588157391238,
WebhookModel1592447867632,
} from './databases/mysqldb/migrations';
import mongodbMigrations from './databases/mongodb/migrations';
import mysqlMigrations from './databases/mysqldb/migrations';
import sqliteMigrations from './databases/sqlite/migrations';
import * as path from 'path';
@ -67,11 +56,7 @@ export async function init(): Promise<IDatabaseCollections> {
entityPrefix,
url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string,
useNewUrlParser: true,
migrations: [
InitialMigration1587563438936,
WebhookModel1592679094242,
CreateIndexStoppedAt1594910478695,
],
migrations: mongodbMigrations,
migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`,
};
@ -123,11 +108,7 @@ export async function init(): Promise<IDatabaseCollections> {
password: await GenericHelpers.getConfigValue('database.mysqldb.password') as string,
port: await GenericHelpers.getConfigValue('database.mysqldb.port') as number,
username: await GenericHelpers.getConfigValue('database.mysqldb.user') as string,
migrations: [
InitialMigration1588157391238,
WebhookModel1592447867632,
CreateIndexStoppedAt1594902918301,
],
migrations: mysqlMigrations,
migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`,
};

View file

@ -2,6 +2,7 @@ import {
Column,
Entity,
PrimaryColumn,
Index,
} from 'typeorm';
import {
@ -9,6 +10,7 @@ import {
} from '../../Interfaces';
@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;
}

View file

@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
import * as config from '../../../../config';
export class InitialMigration1588157391238 implements MigrationInterface {
export default class InitialMigration1588157391238 implements MigrationInterface {
name = 'InitialMigration1588157391238';
async up(queryRunner: QueryRunner): Promise<void> {

View file

@ -5,7 +5,7 @@ import {
import * as config from '../../../../config';
export class WebhookModel1592447867632 implements MigrationInterface {
export default class WebhookModel1592447867632 implements MigrationInterface {
name = 'WebhookModel1592447867632';
async up(queryRunner: QueryRunner): Promise<void> {

View file

@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm";
import * as config from '../../../../config';
export class CreateIndexStoppedAt1594902918301 implements MigrationInterface {
export default class CreateIndexStoppedAt1594902918301 implements MigrationInterface {
name = 'CreateIndexStoppedAt1594902918301';
async up(queryRunner: QueryRunner): Promise<void> {

View file

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import * as config from '../../../../config';
export default class AddWebhookId1610640521099 implements MigrationInterface {
name = 'AddWebhookId1610640521099';
public async up(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query('ALTER TABLE `' + tablePrefix + 'webhook_entity` ADD `webhookId` varchar(255) NULL');
await queryRunner.query('CREATE UNIQUE INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity` (`webhookId`, `method`)');
}
public async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query(
'DROP INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity`',
);
await queryRunner.query('ALTER TABLE `' + tablePrefix + 'webhook_entity` DROP COLUMN `webhookId`');
}
}

View file

@ -1,3 +1,11 @@
export * from './1588157391238-InitialMigration';
export * from './1592447867632-WebhookModel';
export * from './1594902918301-CreateIndexStoppedAt';
import InitialMigration1588157391238 from './1588157391238-InitialMigration';
import WebhookModel1592447867632 from './1592447867632-WebhookModel';
import CreateIndexStoppedAt1594902918301 from './1594902918301-CreateIndexStoppedAt';
import AddWebhookId1610640521099 from './1610640521099-AddWebhookId'
export default [
InitialMigration1588157391238,
WebhookModel1592447867632,
CreateIndexStoppedAt1594902918301,
AddWebhookId1610640521099,
]