How can we help you today? How can we help you today?

Prevent from flyaway clean and migrate based on an env variable

BE and flyway newbie here.
I had to connect to prod data locally, I made the mistake of using a user with write permission and accidentally executed npm db: reset that deleted all production data
"db: reset": "npm run flyway clean && pm run flyway migrate && px prisma db pull && npx prisma db seed"

I usually don't connect to prod, going forward will use read only user, but wanted to double check if I can improve the npm script to prevent from executing flyway clean and: migration when env variable in env file DATABASE_URL points to anything else other than local host.

any ideas?

flywaynewbie
0

Comments

2 comments

  • Peter_Laws
    Welcome aboard newbie!

    There are a few different avenues here.

    The most ironclad would be to globally disable clean and then enable on demand.
    Otherwise evaluating against the environment as you, are will work, however it is potentially slightly more brittle if more environments are added that aren't included in your guard clauses.

    A combination of the two might be your best bet, disabling it, then provisionally enabling base on what the target evaluates to.
    Peter_Laws
    0
  • jack1111
    This comment succinctly informs others about the purpose of the code, emphasizing its function of preventing unintended actions ('flyaway clean') and performing migrations conditionally based on an environment variable.
    jack1111
    0

Add comment

Please sign in to leave a comment.