Skip to content

How to close database in afterMigrate? #252

Closed Answered by romeerez
IlyaSemenov asked this question in Q&A
Discussion options

You must be logged in to vote

Published an update:

  • added beforeChage and afterChange for convenience, docs, this won't help you with this use-case
  • now the change.promise will return a result object which you can use to check if it was rollback, migrate, etc.
import { execSync } from 'node:child_process';

export const change = rakeDb(
  { databaseURL: 'postgres://...' },
  {
    migrationsPath: 'migrations',
  },
);

change.promise.then(({ options, args: [command] }) => {
  if (process.env.NODE_ENV !== 'development') return;

  if (['up', 'down', 'redo', 'recurrent'].includes(command)) {
    // `as string` is safe because you can see that databaseURL was set above
    dump(options[0].databaseURL as string);
  }
});

f…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@IlyaSemenov
Comment options

@romeerez
Comment options

@romeerez
Comment options

Answer selected by romeerez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants