4
2

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 5 years have passed since last update.

Herokuにデプロイ済みのMySQLのロールバック

Posted at

問題

RubyOnRailsアプリケーションを作成して一旦、デプロイ。
heroku rails db:migrateを実行し、成功。

しかし、後からtableを変更したくなったため、既存のmigration_fileを変更。
(※理由 : 無駄なファイルを作成したくない。-> ローカルではdb:migrate:resetしてました。)

herokuでも試してみた。

$ heroku run rails db:migrate:reset
rails aborted!
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database.
If you are sure you want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1
/app/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:61:in `check_protected_environments!'
/app/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.1/lib/active_record/railties/databases.rake:13:in `block (2 levels) in <main>'
/app/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/app/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/app/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/command.rb:48:in `invoke'
/app/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in `<main>'
/app/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/app/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
/app/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/app/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/app/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
/app/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
/app/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
/app/bin/rails:9:in `<main>'
Tasks: TOP => db:check_protected_environments
(See full trace by running task with --trace)

ってクソほどエラー吐かれた。

このとき、heroku上でのMySQLのテーブルとローカルでのスキーマの整合性が取れずに、若干詰まった。

herokuはそもそも、postgresqlを DBとして推奨しているので、文献もあまりなかったので、メモ。

解決策

1: まず、herokuのSettingsをMaintenance Modeに変更

スクリーンショット 2018-11-11 3.55.56.png

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

スクリーンショット 2018-11-11 3.56.10.png

2: 次のコマンドを実行

$ heroku rake db:migrate:redo STEP=10

このコマンドを実行してエラーはかれなかったら、大丈夫!

3: 一応の確認で次のコマンド

$ heroku run rails db:migrate

エラーはかれなかったら、いけてる!

参考文献

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?