2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails db:rollbackで複数個のファイルを差し戻す方法

Posted at

migrationファイルで上段のmigrationファイルをrollbackするのに、一回ずつrials db:rollbackコマンドを入力するのは面倒ですよね。そこで、rails db:rollback STEP=○(数字が入ります)を入力すると、指定した数だけ差し戻されます。例えば、ファイル数が6個ある場合は、6を入力すると全てのファイルが差し戻されます。(rails db:migrate:statusで全てのファイルがdown状態になります。)

% rails db:rollback STEP=5
== 20200313144929 CreateComments: reverting ===================================
-- drop_table(:comments)
-> 0.0051s
== 20200313144929 CreateComments: reverted (0.0069s) ==========================

== 20200313142605 RemoveNameFromTweets: reverting =============================
-- add_column(:tweets, :name, :string)
-> 0.0385s
== 20200313142605 RemoveNameFromTweets: reverted (0.0387s) ====================

== 20200313134628 AddUserIdToTweets: reverting ================================
-- remove_column(:tweets, :user_id, :integer)
-> 0.0296s
== 20200313134628 AddUserIdToTweets: reverted (0.0297s) =======================

== 20200313092641 AddNicknameToUsers: reverting ===============================
-- remove_column(:users, :nickname, :string)
-> 0.0362s
== 20200313092641 AddNicknameToUsers: reverted (0.0364s) ======================

== 20200313085008 DeviseCreateUsers: reverting ================================
-- remove_index(:users, {:column=>:reset_password_token})
-> 0.0253s

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?