mongo-migrate-ts icon indicating copy to clipboard operation
mongo-migrate-ts copied to clipboard

migrate down doesn't finish

Open naffarn opened this issue 6 months ago • 1 comments

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.

naffarn avatar Jun 19 '25 05:06 naffarn

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();
+        }
       });

naffarn avatar Jun 19 '25 06:06 naffarn