mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
fix(core): Fix the db:revert
command (no-changelog) (#6506)
This commit is contained in:
parent
42a9e20e32
commit
8dc828b704
|
@ -4,6 +4,8 @@ import { DataSource as Connection } from 'typeorm';
|
||||||
import { LoggerProxy } from 'n8n-workflow';
|
import { LoggerProxy } from 'n8n-workflow';
|
||||||
import { getLogger } from '@/Logger';
|
import { getLogger } from '@/Logger';
|
||||||
import { getConnectionOptions } from '@/Db';
|
import { getConnectionOptions } from '@/Db';
|
||||||
|
import type { Migration } from '@db/types';
|
||||||
|
import { wrapMigration } from '@db/utils/migrationHelpers';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
|
|
||||||
export class DbRevertMigrationCommand extends Command {
|
export class DbRevertMigrationCommand extends Command {
|
||||||
|
@ -34,6 +36,8 @@ export class DbRevertMigrationCommand extends Command {
|
||||||
logging: ['query', 'error', 'schema'],
|
logging: ['query', 'error', 'schema'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(connectionOptions.migrations as Migration[]).forEach(wrapMigration);
|
||||||
|
|
||||||
this.connection = new Connection(connectionOptions);
|
this.connection = new Connection(connectionOptions);
|
||||||
await this.connection.initialize();
|
await this.connection.initialize();
|
||||||
await this.connection.undoLastMigration();
|
await this.connection.undoLastMigration();
|
||||||
|
|
|
@ -72,12 +72,12 @@ export const wrapMigration = (migration: Migration) => {
|
||||||
|
|
||||||
const { up, down } = migration.prototype;
|
const { up, down } = migration.prototype;
|
||||||
Object.assign(migration.prototype, {
|
Object.assign(migration.prototype, {
|
||||||
up: async (queryRunner: QueryRunner) => {
|
async up(queryRunner: QueryRunner) {
|
||||||
logMigrationStart(migrationName);
|
logMigrationStart(migrationName);
|
||||||
await up.call(this, { queryRunner, ...context });
|
await up.call(this, { queryRunner, ...context });
|
||||||
logMigrationEnd(migrationName);
|
logMigrationEnd(migrationName);
|
||||||
},
|
},
|
||||||
down: async (queryRunner: QueryRunner) => {
|
async down(queryRunner: QueryRunner) {
|
||||||
await down?.call(this, { queryRunner, ...context });
|
await down?.call(this, { queryRunner, ...context });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -61,9 +61,7 @@ export async function init() {
|
||||||
if (dbType === 'sqlite') {
|
if (dbType === 'sqlite') {
|
||||||
// no bootstrap connection required
|
// no bootstrap connection required
|
||||||
await Db.init(getSqliteOptions({ name: testDbName }));
|
await Db.init(getSqliteOptions({ name: testDbName }));
|
||||||
}
|
} else if (dbType === 'postgresdb') {
|
||||||
|
|
||||||
if (dbType === 'postgresdb') {
|
|
||||||
let bootstrapPostgres;
|
let bootstrapPostgres;
|
||||||
const pgOptions = getBootstrapDBOptions('postgres');
|
const pgOptions = getBootstrapDBOptions('postgres');
|
||||||
|
|
||||||
|
@ -92,9 +90,7 @@ export async function init() {
|
||||||
await bootstrapPostgres.destroy();
|
await bootstrapPostgres.destroy();
|
||||||
|
|
||||||
await Db.init(getDBOptions('postgres', testDbName));
|
await Db.init(getDBOptions('postgres', testDbName));
|
||||||
}
|
} else if (dbType === 'mysqldb' || dbType === 'mariadb') {
|
||||||
|
|
||||||
if (dbType === 'mysqldb') {
|
|
||||||
const bootstrapMysql = await new Connection(getBootstrapDBOptions('mysql')).initialize();
|
const bootstrapMysql = await new Connection(getBootstrapDBOptions('mysql')).initialize();
|
||||||
await bootstrapMysql.query(`CREATE DATABASE ${testDbName}`);
|
await bootstrapMysql.query(`CREATE DATABASE ${testDbName}`);
|
||||||
await bootstrapMysql.destroy();
|
await bootstrapMysql.destroy();
|
||||||
|
|
Loading…
Reference in a new issue