[Beginner] I want to modify the migration file-How to use rollback-

When I first started studying, I tried to make something myself and immediately erased it if I made a mistake. What makes me particularly confused is around migration ... Rollback is a must-have for those who have always erased it.

What is rollback?

Rewind Being able to return the processing before committing one by one

How to use

Oh, when I think I made a mistake First, let's look at the current situation.

$ rails db:migrate:status
 Status   Migration ID    Migration Name
up date Devise create users
up Date Add name to users
up date Create posts

If it is up, it cannot be read even if you edit the migration file. Therefore,

$ rails db:rollback
$ rails db:migrate:status
 Status   Migration ID    Migration Name
up date Devise create users
up Date Add name to users
down date Create posts

You can edit it by setting the state to down. When you want to roll back multiple migration files at the same time

$ rails db:rollback STEP=2
$ rails db:migrate:status
 Status   Migration ID    Migration Name
down date Devise create users
down date Add name to users
down date Create posts

It looks like this. After making it down, fix it and execute the rails db: migrate command again.

By the way, when you want to start over

$ rails db:rollback VERSION=0


At first, if you make a mistake, it's faster to erase it, but just remembering this will make you feel much better.

Recommended Posts

[Beginner] I want to modify the migration file-How to use rollback-
I want to use the Java 8 DateTime API slowly (now)
I want to use the sanitize method other than View.
I want to use DBViewer with Eclipse 2018-12! !!
I want to use @Autowired in Servlet
I want you to use Enum # name () for the Key of SharedPreference
I want to use java8 forEach with index
I want to var_dump the contents of the intent
When you want to use the method outside
I want to truncate after the decimal point
I want to get the value in Ruby
I want you to use Scala as Better Java for the time being
[Eclipse] I want to use the completion function, but I want to manage to confirm the completion with spaces.
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to embed any TraceId in the log
Tokoro I rewrote in the migration from Wicket 7 to 8
I want to use fish shell in Laradock too! !!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to judge the range using the monthly degree
I want to know the answer of the rock-paper-scissors app
[Rails] I don't know how to use the model ...
I want to display the name of the poster of the comment
[Beginner] Discover the N + 1 problem! How to use Bullet
I want to dark mode with the SWT app
[Android Studio] I want to use Maven library on Android
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I want to return the scroll position of UITableView!
I want to simplify the log output on Android
I want to add a delete function to the comment function
[Rails] [bootstrap] I want to change the font size responsively
I want to convert characters ...
(´-`) .. oO (I want to easily find the standard output "Hello".
How to use JUnit (beginner)
I want to use Java Applet easily on the command line without using an IDE
I want to bring Tomcat to the server and start the application
I want to call a method and count the number
I want to create a form to select the [Rails] category
I want to put the JDK on my Mac PC
I want to give a class name to the select attribute
I want to recursively search the class list under the package
I want to transition to the same screen in the saved state
I want to use FireBase to display a timeline like Twitter
I want to return multiple return values for the input argument
[Ruby] I want to reverse the order of the hash table
How to rollback migration files
I want to pass the startup command to postgres with docker-compose.
I want to simplify the conditional if-else statement in Java
I want to give edit and delete permissions only to the poster
I want to understand the flow of Spring processing request parameters
I want to use swipeback on a screen that uses XLPagerTabStrip
I want to return to the previous screen with kotlin and java!
The story of Collectors.groupingBy that I want to keep for posterity
[Eclipse] I want to open the same file twice [Split editor]
What I did in the migration from Spring Boot 1.4 series to 2.0 series
I want to limit the input by narrowing the range of numbers
About the matter that I was addicted to how to use hashmap
I want to add the disabled option to f.radio_button depending on the condition