1
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?

【Render】テーブルの変更がRenderに反映できない

Posted at

記事概要

本番環境のRenderにあるテーブルが変更されない場合の対応方法について、まとめる

事象

Renderのテーブルに変更が反映されない

  • カラムの追加などのテーブルの変更を行った
  • ローカルでは、変更内容が正しく反映する
  • Renderでデプロイを行った際、エラー発生しない

対応方法

注意点:作業前のデータは全て削除されるため、データが全消去されても問題ない場合のみ実行する

  1. Renderで作成したデータベースをリセットするため、VSCodeでファイルを修正する
    bin/render-build.sh
    #!/usr/bin/env bash
    # exit on error
    set -o errexit
    
    bundle install
    bundle exec rake assets:precompile
    bundle exec rake assets:clean
    # bundle exec rake db:migrate
    DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rake db:migrate:reset
    
    • DISABLE_DATABASE_ENVIRONMENT_CHECK=1は、本番環境のデータベースを削除するために必要な設定。通常は削除できないようになっている
    • bundle exec rake db:migrate:resetは、データベースをリセットするためのコマンド。下記3つを実行したことになる
      • rake db:drop(データベースの削除)
      • rake db:create(データベースの作成)
      • rake db:migrate(マイグレーションファイルの実行)
  2. TablePlus.appを終了する
  3. GitHubにプッシュして更新する
  4. GitHubにコードをプッシュすると、Renderのデプロイが実行される
  5. デプロイ完了後、アプリを操作したり、TablePlusでテーブルの内容を確認する
    ※正しく変更されていることを確認
  6. 1.の修正を元に戻すため、VSCodeでファイルを修正する
    bin/render-build.sh
    #!/usr/bin/env bash
    # exit on error
    set -o errexit
    
    bundle install
    bundle exec rake assets:precompile
    bundle exec rake assets:clean
    bundle exec rake db:migrate
    
1
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
1
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?