shimgo
8/23/2017 - 1:44 PM

rake db:setupで立ち上げたるとDB内のデータが削除される

rake db:setupで立ち上げたるとDB内のデータが削除される

db:setup内ではdb:scheme:loadの処理を含んでいる。db:scheme:loadするとテーブルが再作成されるため、データが消えてしまう。
データを消さずにdockerのentrypointのようなところで毎回DBのセットアップをしたいならdb:create、db:migrateを個別に実行すればよい。
以下参考

db:migrate runs (single) migrations that have not run yet.
db:create creates the database
db:drop deletes the database
db:schema:load creates tables and columns within the (existing) database following schema.rb
db:setup does db:create, db:schema:load, db:seed
db:reset does db:drop, db:setup