How to use seeding for filling data in database
Previously we used the rails migration in order to fill data but it was a not good practice because we mixed schema and data changes - https://guides.rubyonrails.org/active_record_migrations.html
Create seed​
rails g seed_migration AddFoo
A new file will be created under db/data/ using rails migration convention:​
db/data/20230124162007_add_foo.rb
Some example on our code base​
db/data/20221101042026_add_foo.rb
Running the migrations​
To run all pending migrations, simply use​
rake seed:migrate
If needed, you can run a specific migration:​
rake seed:migrate MIGRATION=20140407162007_add_foo.rb
Rollback​
Rolling back the last migration is as simple as:​
rake seed:rollback
More details here https://github.com/pboling/seed_migration
How it works on deploy​
Your created seeds will automaticly run on staging or prod