Rails - How to rollback database migration

To rollback last migration use command:

$ rake db:rollback
==  AddAccessedAtToAssets: reverting ==========================================
-- remove_column(:assets, :accessed_at)
   -> 0.2357s
==  AddAccessedAtToAssets: reverted (0.2359s) =================================

To rollback (as an example) last three migrations use the STEP parameter:

$ rake db:rollback STEP=3
==  AddFolderIdToAssets: reverting ============================================
-- remove_column(:assets, :folder_id)
   -> 0.2230s
==  AddFolderIdToAssets: reverted (0.2232s) ===================================

==  CreateFolders: reverting ==================================================
-- drop_table(:folders)
   -> 0.0723s
==  CreateFolders: reverted (0.0724s) =========================================

==  AddAttachmentUploadedFileToAsset: reverting ===============================
-- remove_column(:assets, :uploaded_file_file_name)
   -> 0.2546s
-- remove_column(:assets, :uploaded_file_content_type)
   -> 0.2616s
-- remove_column(:assets, :uploaded_file_file_size)
   -> 0.2263s
-- remove_column(:assets, :uploaded_file_updated_at)
   -> 0.2342s
==  AddAttachmentUploadedFileToAsset: reverted (0.9774s) ======================
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu