mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
3137de2585
* ✨ change FE to handle new object type * 🚸 improve UX of handling invalid credentials * 🚧 WIP * 🎨 fix typescript issues * 🐘 add migrations for all supported dbs * ✏️ add description to migrations * ⚡ add credential update on import * ⚡ resolve after merge issues * 👕 fix lint issues * ⚡ check credentials on workflow create/update * update interface * 👕 fix ts issues * ⚡ adaption to new credentials UI * 🐛 intialize cache on BE for credentials check * 🐛 fix undefined oldCredentials * 🐛 fix deleting credential * 🐛 fix check for undefined keys * 🐛 fix disabling edit in execution * 🎨 just show credential name on execution view * ✏️ remove TODO * ⚡ implement review suggestions * ⚡ add cache to getCredentialsByType * ⏪ use getter instead of cache * ✏️ fix variable name typo * 🐘 include waiting nodes to migrations * 🐛 fix reverting migrations command * ⚡ update typeorm command * ✨ create db:revert command * 👕 fix lint error Co-authored-by: Mutasem <mutdmour@gmail.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable no-console */
|
|
import { Command, flags } from '@oclif/command';
|
|
import { Connection, ConnectionOptions, createConnection } from 'typeorm';
|
|
import { LoggerProxy } from 'n8n-workflow';
|
|
|
|
import { getLogger } from '../../src/Logger';
|
|
|
|
import { Db } from '../../src';
|
|
|
|
export class DbRevertMigrationCommand extends Command {
|
|
static description = 'Revert last database migration';
|
|
|
|
static examples = ['$ n8n db:revert'];
|
|
|
|
static flags = {
|
|
help: flags.help({ char: 'h' }),
|
|
};
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
async run() {
|
|
const logger = getLogger();
|
|
LoggerProxy.init(logger);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-shadow, @typescript-eslint/no-unused-vars
|
|
const { flags } = this.parse(DbRevertMigrationCommand);
|
|
|
|
let connection: Connection | undefined;
|
|
try {
|
|
await Db.init();
|
|
connection = Db.collections.Credentials?.manager.connection;
|
|
|
|
if (!connection) {
|
|
throw new Error(`No database connection available.`);
|
|
}
|
|
|
|
const connectionOptions: ConnectionOptions = Object.assign(connection.options, {
|
|
subscribers: [],
|
|
synchronize: false,
|
|
migrationsRun: false,
|
|
dropSchema: false,
|
|
logging: ['query', 'error', 'schema'],
|
|
});
|
|
|
|
// close connection in order to reconnect with updated options
|
|
await connection.close();
|
|
connection = await createConnection(connectionOptions);
|
|
|
|
await connection.undoLastMigration();
|
|
await connection.close();
|
|
} catch (error) {
|
|
if (connection) await connection.close();
|
|
|
|
console.error('Error reverting last migration. See log messages for details.');
|
|
logger.error(error.message);
|
|
this.exit(1);
|
|
}
|
|
|
|
this.exit();
|
|
}
|
|
}
|