markgardner / node-flywaydb

NodeJs wrapper for flywaydb cli
Apache License 2.0
60 stars 26 forks source link

Elegant Failure #29

Closed jamesmart77 closed 3 years ago

jamesmart77 commented 3 years ago

Hey there, really great library here - a big help for our team!

When we deploy our app, dynamic secrets are injected into the application. When we start the app on deployment we run the flyway migration and this works well because the secrets needed to migrate are still valid (2hr life span). Other read-write creds allow the app to perform DB transactions while the app continues running after the two-hour mark.

Here where things get a little interesting, we have a curfew on the app so it'll go to sleep during off hours (saving $) and when it tries to start back up, it fails because the migrate (required on startup) now fails due to the creds being expired.

This is our NPM script for the migration: "migrate": "flyway -c db/flyway.js migrate

This is how we start the app on deployment (and when coming off curfew): npm run migrate && npm run server

Question: since only the config is passed to the flyway migrate command, do you know if there is an elegant way to fail the migration task?

I'm going to try the following, but wasn't sure if you had any other options in case this fails? "migrate": "flyway -c db/flyway.js migrate || true

markgardner commented 3 years ago

Hey James,

Glad to hear the library helps. So the terminal fall back (flyway -c db/flyway.js migrate || echo 'Migration Failed') works but may hide a different failure (ie db script syntax error). You could attempt a connection and ping to your database in the config.js. If the connect fails, print some log message and call process.exit(0).

Hope this helps.

markgardner commented 3 years ago

let me know if you need anything