[RUBY] How to rollback migration files

Introduction

When I wanted to change the column name when creating a flea market app at a certain programming school, I needed to roll back the migration file, so I will write what I checked at that time.

1. How to send back migration files one by one

First run the following in the terminal

$ rails db:rollback

$ rails db:migrate:status

↓ I think it will be displayed in the terminal like this
 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200510074001  Create spending categories
   up     20200510074005  Create income categories
   up     20200510074056  Create incomes
  down    20200510074140  Create spendings

2. Send back multiple files

You can send back multiple files by specifying the number with STEP = at the end as shown below. This time, I will send back all four.

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

↓ I think it will be displayed in the terminal like this
 Status   Migration ID    Migration Name
--------------------------------------------------
  down    20200510074001  Create spending categories
  down    20200510074005  Create income categories
  down    20200510074056  Create incomes
  down    20200510074140  Create spendings

3. Send back only arbitrary migration files

If you specify "Migration ID" in VERSION as shown below, you can return only the selected migration file.

$ rails db:migrate:down VERSION=20200510074001 

$ rails db:migrate:status

↓ I think it will be displayed in the terminal like this
 Status   Migration ID    Migration Name
--------------------------------------------------
  down    20200510074001  Create spending categories
   up     20200510074005  Create income categories
   up     20200510074056  Create incomes
   up     20200510074140  Create spendings

Thank you for watching till the end! !!

I hope you found this article helpful: pray_tone2:

Recommended Posts

How to rollback migration files
Rails "How to delete NO FILE migration files"
How to decompile java class files
How to share files with Docker Toolbox
How to use binding.pry for view files
How to delete the migration file NO FILE
[Java] How to output and write files!
Introduction to migration
How to update pre-built files in docker container
Note how to rollback Mysql deployed on Heroku
How to build parquet-tools and merge Parquet files
[Rails] About migration files
Add files to jar files
How to develop OpenSPIFe
Introduction to JAR files
How to call AmazonSQSAsync
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use java.util.logging
How to use map
How to adapt Bootstrap
How to use Twitter4J
How to use active_hash! !!
How to install Docker
How to use hidden_field_tag
How to write dockerfile
How to uninstall Rails
How to install docker-machine
[How to use label]
How to make shaded-jar
How to write docker-compose
How to use identity
How to use hashes
How to write Mockito
How to create docker-compose
How to use JUnit 5
How to install MySQL
How to write migrationfile
How to build android-midi-lib
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to install ngrok
How to type backslash \
How to concatenate strings
How to input / output IBM mainframe files in Java?
How to handle TSV files and CSV files in Ruby
How to Syntax Highlight files like Dockerfile.production in Pycharm
How to delete BOM (UTF-8)
How to create an application
[Java] How to use Map
[Beginner] I want to modify the migration file-How to use rollback-
How to resolve Sprockets :: DoubleLinkError
[rails] How to post images
[AWS] How to check logs
How to use Maven to place resource files outside the JAR