Prevent from flyaway clean and migrate based on an env variable
flywaynewbie
Posts: 1 New member
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?
Answers
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.