【heroku】のDBをリセットしたくて......できた!
herokuのpostgresのDBをリセットしたくて色々実行したら
案外簡単に出来たけど、また次したら忘れてしまいそう
だからメモ!
まずは失敗をメモ
$ heroku run rake db:reset
をしたら最初は出来てたけど途中からエラーになった
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a dest ructive action against your 'production' database. If you are sure you want to continue, run the same command with the envir onment variable: DISABLE_DATABASE_ENVIRONMENT_CHECK=1
これはRails5からproductionモードではDBを破壊する系のコマンド実行
を防止する機能が追加されたみたい。
次に成功メモ
$ heroku pg:reset DATABASE_URL ▸ WARNING: Destructive action ▸ postgresql-colorful-91908 will lose all of its data ▸ ▸ To proceed, type herokuのアプリ名 or ▸ re-run this command with --confirm ▸ herokuのアプリ名 > herokuのアプリ名
これで成功したと思われる!
ドキドキしながら実行してみる
$ heroku run rails db:migrate
ズラーッと出てきて成功!!
よしっと思い次はseedsファイルの初期データを追加する
$ heroku run rails db:seed
これもズラーッと出てきて成功!!
更に確認しておこう
$ heroku pg:psql-a herokuのアプリ名 . . . . DATABASE=>select * from posts;