Masatoshi Nishiguchi
Software Engineer

Undoing things in Rails apps

rails

This is my memo on Undoing things in Rails apps.

Undo “generate”

rails generate controller FooBars baz quux
rails destroy controller FooBars

rails generate model Foo bar:string baz:integer
rails destroy model Foo

rails generate scaffold Micropost content:text user:references
rails destroy scaffold Micropost

Undo “migrate”

bundle exec rake db:migrate
bundle exec rake db:rollback

# To go all the way back to the beginning, we can use
bundle exec rake db:migrate VERSION=0

Reset database in development

rake db:drop && rake db:create && rake db:migrate && rake db:seed

Reset database in production (Heroku)

heroku pg:reset DATABASE

Reference