Rodolfo Bandeira

Rodolfo Bandeira

software, electronics, security, devops, thoughts

Rolling back RubyOnRails Migration

Creating RubyOnRails migrations also allow us to rollback an migration after executing it.

Two common ways to write migrations is either using def change which is the default from Rails by the way, or using def up and def down.

When using def change, Rails is smart enough and tries to rollback automatically. And of course if you have something crazy like a raw query on your migration, you can use the old school def up, def down.

Basically, you just need to get the timestamp that it is usually on the migration’s filename and run:

bundle exec rake db:migrate:redo VERSION=20180330164947

Another alternative is reset your db everytime you make a mistake. In dev mode it is still OK, but taking advantage on core features is even better.

Cheers, Rodolfo

Last modified:

LinkedIn
WhatsApp