chore: import DH V2 D5.6.4 production baseline
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import 'reflect-metadata';
|
||||
import { migrationDataSource } from './data-source';
|
||||
|
||||
type MigrationCommand = 'run' | 'show' | 'revert';
|
||||
|
||||
function readCommand(): MigrationCommand {
|
||||
const command = process.argv[2];
|
||||
if (command === 'run' || command === 'show' || command === 'revert') {
|
||||
return command;
|
||||
}
|
||||
throw new Error('Expected migration command: run, show or revert');
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const command = readCommand();
|
||||
await migrationDataSource.initialize();
|
||||
|
||||
try {
|
||||
if (command === 'run') {
|
||||
const migrations = await migrationDataSource.runMigrations({
|
||||
transaction: 'each',
|
||||
});
|
||||
console.log(`Applied migrations: ${migrations.length}`);
|
||||
for (const migration of migrations) console.log(`- ${migration.name}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === 'revert') {
|
||||
await migrationDataSource.undoLastMigration({ transaction: 'each' });
|
||||
console.log('Last migration reverted');
|
||||
return;
|
||||
}
|
||||
|
||||
const hasPendingMigrations = await migrationDataSource.showMigrations();
|
||||
console.log(
|
||||
hasPendingMigrations
|
||||
? 'Pending migrations: yes'
|
||||
: 'Pending migrations: no',
|
||||
);
|
||||
} finally {
|
||||
await migrationDataSource.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error: unknown) => {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||
console.error(`Migration command failed: ${message}`);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user