From 8dc828b704e4747ff0fee972250e4cd9eb71621f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Thu, 22 Jun 2023 09:06:31 +0200 Subject: [PATCH] fix(core): Fix the `db:revert` command (no-changelog) (#6506) --- packages/cli/src/commands/db/revert.ts | 4 ++++ packages/cli/src/databases/utils/migrationHelpers.ts | 4 ++-- packages/cli/test/integration/shared/testDb.ts | 8 ++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/db/revert.ts b/packages/cli/src/commands/db/revert.ts index 56de3b5663..07f0a09e02 100644 --- a/packages/cli/src/commands/db/revert.ts +++ b/packages/cli/src/commands/db/revert.ts @@ -4,6 +4,8 @@ import { DataSource as Connection } from 'typeorm'; import { LoggerProxy } from 'n8n-workflow'; import { getLogger } from '@/Logger'; import { getConnectionOptions } from '@/Db'; +import type { Migration } from '@db/types'; +import { wrapMigration } from '@db/utils/migrationHelpers'; import config from '@/config'; export class DbRevertMigrationCommand extends Command { @@ -34,6 +36,8 @@ export class DbRevertMigrationCommand extends Command { logging: ['query', 'error', 'schema'], }; + (connectionOptions.migrations as Migration[]).forEach(wrapMigration); + this.connection = new Connection(connectionOptions); await this.connection.initialize(); await this.connection.undoLastMigration(); diff --git a/packages/cli/src/databases/utils/migrationHelpers.ts b/packages/cli/src/databases/utils/migrationHelpers.ts index 21d731e39a..0221e7345d 100644 --- a/packages/cli/src/databases/utils/migrationHelpers.ts +++ b/packages/cli/src/databases/utils/migrationHelpers.ts @@ -72,12 +72,12 @@ export const wrapMigration = (migration: Migration) => { const { up, down } = migration.prototype; Object.assign(migration.prototype, { - up: async (queryRunner: QueryRunner) => { + async up(queryRunner: QueryRunner) { logMigrationStart(migrationName); await up.call(this, { queryRunner, ...context }); logMigrationEnd(migrationName); }, - down: async (queryRunner: QueryRunner) => { + async down(queryRunner: QueryRunner) { await down?.call(this, { queryRunner, ...context }); }, }); diff --git a/packages/cli/test/integration/shared/testDb.ts b/packages/cli/test/integration/shared/testDb.ts index 4e5f4e9528..c9df9026b8 100644 --- a/packages/cli/test/integration/shared/testDb.ts +++ b/packages/cli/test/integration/shared/testDb.ts @@ -61,9 +61,7 @@ export async function init() { if (dbType === 'sqlite') { // no bootstrap connection required await Db.init(getSqliteOptions({ name: testDbName })); - } - - if (dbType === 'postgresdb') { + } else if (dbType === 'postgresdb') { let bootstrapPostgres; const pgOptions = getBootstrapDBOptions('postgres'); @@ -92,9 +90,7 @@ export async function init() { await bootstrapPostgres.destroy(); await Db.init(getDBOptions('postgres', testDbName)); - } - - if (dbType === 'mysqldb') { + } else if (dbType === 'mysqldb' || dbType === 'mariadb') { const bootstrapMysql = await new Connection(getBootstrapDBOptions('mysql')).initialize(); await bootstrapMysql.query(`CREATE DATABASE ${testDbName}`); await bootstrapMysql.destroy();