[RUBY] [Rails] Modify migrate file (rails db: rollback STEP =)

Hello, this is tt_tsutsumi. This time too, I will explain how to change the migrate file. I hope this article helps somebody.

https://qiita.com/tt_tsutsumi/items/ea8bc346d5b9cb21e05b

↑↑↑

In the previous article, you can change the migrate file, etc. Among them, there was a story that only one file can be downed, but This time, I will describe how to bring down any file at once.

  1. rails db:migrate:status First of all, let's check the operating status of migrate of the application you are currently creating as before. Enter the code below at the console.
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     year/month/day  Devise create users
   up     year/month/day  Create spots

  1. rails db:rollback STEP=2

Add ** STEP = 2 ** after the previous ** rails db: rollback ** and execute. The meaning of this code is to down ** the file from the current file up to ** 2 steps ago. When executed, it will be as follows.

$ rails db:rollback STEP=2
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   down     year/month/day  Devise create users
   down     year/month/day  Create spots

If you want to change or delete multiple files at once, it is faster to use STEP. However, please note that if you do not use it after checking it, everything may go down. 3. rails db:migrate

When the changes are complete, save and do ** rails db: migrate **. Even if you go back several steps in STEP, all will be changed to up in one migrate.

$ rails db:migrate
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     year/month/day  Devise create users
   up     year/month/day  Create spots

This completes batch modification and saving of migrate files. Thank you for visiting !!

Recommended Posts

[Rails] Modify migrate file (rails db: rollback STEP =)
[Rails] Modify migrate file (rails db: rollback)
rails db: migrate failed!
Error in rails db: migrate
[heroku] run rails db: migrate doesn't work
After all, what is [rails db: migrate] doing?
rails db: 〇〇 Summary
[Rails] "private method` String' called ~ "error when db: migrate
About the error that occurred when adding the column name in rails (rails db: migrate, rails db: rollback, add)
[Rails] rails db command summary
# What to do if you accidentally do rails db: migrate: drop
PG :: DatatypeMismatch error when doing heroku run rails db: migrate