Best Practices for Incremental Seeds with Capistra

2019-08-31 13:36发布

问题:

RoR 3.2.13 and 3.0.1 capistrano

My application requires initial data via rake db:seed. My continuous integration server does automatic deployment each time someone join a new feature and all test pass. Among the latest task is rake db:seed.

The first time works fine, but in the following fail the seeds because some records already exist in database.

Which strategy suggest me to run the seeds incrementally.

Note that:

  • The seeds may vary over time.
  • The application already contains data on production.
  • Should be run automatically from the Continuous Integration server.

Who should have the responsibility not to repeat information: Capistrano, the seed itself, the application, continuous integration server?

回答1:

In our team we are using migrations for change db schema and also existing data.



回答2:

The way for seeds is seed-fu. With seed-fu we can make idempotents seeds and means you can run sometimes without alter final result. the way for different seeds by environment or deploys is seedbank