c-hive / guides

Guides for code style, way of working and other development concerns
MIT License
26 stars 5 forks source link

Add Rails best practice around migrations and seeds #45

Open thisismydesign opened 4 years ago

thisismydesign commented 4 years ago

https://stackoverflow.com/a/2667747/2771889

avoid seeding in migrations. if you change the model (e.g. add a mandatory field) old migrations will no longer work. either you'd have to update existing migrations, which is ill-advised ("In general, editing existing migrations is not a good idea." https://edgeguides.rubyonrails.org/active_record_migrations.html#changing-existing-migrations), or avoid db:migrate(:*) in favor of db:schema:load.

avoid bin/rails db:create db:migrate && bin/rails db:seed

e.g. if there's a non-optional relation added to an initializer that used to be optional before