Rails: Is it bad to have an irreversible migration?

If you are dealing with production-grade systems then yes, it is very bad. If it is your own pet project, then anything is allowed (if nothing else, it will be a learning experience 🙂 though chances are that sooner rather than later, even in a pet project, you will find yourself having put a cross … Read more

mysql transaction – roll back on any exception

You can use 13.6.7.2. DECLARE … HANDLER Syntax in the following way: DELIMITER $$ CREATE PROCEDURE `sp_fail`() BEGIN DECLARE `_rollback` BOOL DEFAULT 0; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET `_rollback` = 1; START TRANSACTION; INSERT INTO `tablea` (`date`) VALUES (NOW()); INSERT INTO `tableb` (`date`) VALUES (NOW()); INSERT INTO `tablec` (`date`) VALUES (NOW()); — FAIL IF … Read more

What is the difference between rollback, backout and strip in the Mercurial Eclipse plugin?

These commands all come from Mercurial itself, and there are plenty of good compare/contrast posts for them. However, here they are in brief: rollback: one-level undo. Will undo the last pull or commit (can be dangerous) backout: create a new commit that is the inverse of a given commit. Net effect is an undo, but … Read more

What are the differences between ‘revert’, ‘amend,’ ‘rollback’, and ‘undo’ a commit?

The terms revert and amend have a well defined meaning in Git. In contrast, rollback and undo do not have such a well defined meaning, and are open to interpretation. Reverting a commit… …means creating (on the current branch) a new commit that applies the inverse changes that another commit introduced. It’s the preferred approach … Read more

Rake db:migrate – how do I undo all migrations and redo them

Rolling back all migrations To rollback all migrations the best solution is the one @Claudio Floreani proposed: rake db:migrate VERSION=0 This will rollback every migration. You can read why this is the best approach in his answer. Then, run all migrations again with rake db:migrate Resetting the database Reset rake db:migrate:reset #runs db:drop db:create db:migrate … Read more

How to roll back migrations using Flyway?

While Flyway supports rollbacks (as a commercial-only feature) its use is discouraged: https://flywaydb.org/documentation/command/undo While the idea of undo migrations is nice, unfortunately it sometimes breaks down in practice. As soon as you have destructive changes (drop, delete, truncate, …), you start getting into trouble. And even if you don’t, you end up creating home-made alternatives … Read more