Prevent from flyaway clean and migrate based on an env variable

flywaynewbieflywaynewbie Posts: 1 New member
edited May 17, 2024 10:19AM in PostgreSQL
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?

Tagged:

Answers

  • 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.
    Kind regards
    Peter Laws | Redgate Software
    Have you visited our Help Center?
  • jack1111jack1111 Posts: 4 New member
    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.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file