--Those who want to know how to operate the migration file
$ rails -v
Rails 6.0.3.1
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
$ mysql --version
mysql Ver 14.14 Distrib 5.7.29, for osx10.15 (x86_64) using EditLine wrapper
Suppose you want to delete the file Add column to users
--Check the migration ID of the file you want to delete
$ rails db:migrate:status
Status Migration ID Migration Name
--------------------------------------------------
up 20200618162841 Create tweetposts
up 20200620004226 Change tweetposts to tweets
down 20200621075518 Create posts
down 20200623102444 Change posts to chats
down 20200627042358 Create users
up 20200627080839 Create users
up 20200627083356 Add column to users
down 20200627220915 Change datatype content of chats
down 20200710035709 Add user id to tweets
--Specify ID and bring down
$ rails db:migrate:down VERSION=Add column to users
--Move the downed file to the trash
$ rm db/migrate/20200703201452_add_column_to_users.rb
********** no file **********
I want to delete the file in the up state with the file
--Check the migration ID of the file you want to delete
$ rails db:migrate:status
Status Migration ID Migration Name
--------------------------------------------------
up 20200618162841 Create tweetposts
up 20200620004226 Change tweetposts to tweets
down 20200621075518 Create posts
down 20200623102444 Change posts to chats
down 20200627042358 Create users
up 20200627080839 Create users
up 20200627083356 Add column to users
down 20200627220915 Change datatype content of chats
up 20200703201452 ********** NO FILE **********
down 20200710035709 Add user id to tweets
--Create a file with the same name as the deleted migration file name
$ touch db/migrate/20200703201452_add_column_to_users.rb
20200703201452_add_column_to_users.rb
class AddColumnToUsers < ActiveRecord::Migration
def change
end
end
$ rails db:migrate:down VERSION=20200703201452
$ rm db/migrate/20200703201452_add_column_to_users.rb
Recommended Posts