migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Feature request: preventing "migrate down" command

Open srdjan-mijatov opened this issue 8 years ago • 1 comments

"migrate down" is useful in development, but it can be catastrophic in production. It would be nice to prevent "down" part of the migration scripts on production servers (by using some bool property).

srdjan-mijatov avatar May 19 '17 08:05 srdjan-mijatov

There is a simple-enough solution using a hook.

Create a hook script 'fail.js' in $MIGRATIONS_HOME/hooks directory with some invalid content. For example...

>>> This hook script saves you from making a critical mistake ;D

And specify the script as a before-down hook in your production.properties.

hook_before_down=js:fail.js

Now, migrate down against production never succeeds.

------------------------------------------------------------------------
-- MyBatis Migrations - down
------------------------------------------------------------------------
========== Applying JSR-223 hook : fail.js =====================================
------------------------------------------------------------------------
-- MyBatis Migrations FAILURE
-- Total time: 0s
-- Finished at: Sat May 20 02:57:18 JST 2017
-- Final Memory: 35M/479M
------------------------------------------------------------------------

ERROR: Error undoing last migration.  Cause: javax.script.ScriptException: <eval>:17:0 Expected an operand but found >>>
>>> This hook script saves you from making a critical mistake ;D
^ in <eval> at line number 17 at column number 0

Please see the doc for the details about hooks.

harawata avatar May 19 '17 18:05 harawata

closing as noted how to address.

hazendaz avatar May 07 '23 05:05 hazendaz