mongo-migrate-ts
mongo-migrate-ts copied to clipboard
migrate down doesn't finish
I am using the index.ts method to run my migrations.
Migrating up works fine.
When I migrate down, the last migration is reversed correctly, but the migration process stops responding and never exits. Ctrl + C doesn't even end the process, I need to exit the terminal manually.
Happy to create a PR to fix.
From my local tinkering, looks like it's as simple as adding a try/catch with a process.exit() to the down cli command:
--- a/lib/cli.ts
+++ b/lib/cli.ts
@@ -74,18 +74,31 @@ export const cli = (config?: Config): void => {
program.outputHelp();
process.exit(-1);
}
-
- await down({
- config,
- mode: opts.last ? 'last' : 'all',
- });
+ try {
+ await down({
+ config,
+ mode: opts.last ? 'last' : 'all',
+ });
+ } catch (e) {
+ console.error(e);
+ process.exitCode = 1;
+ } finally {
+ process.exit();
+ }
});