2

I've setup my migration files and my seeder files with fake data and they're working nicely. I'm about to commit my work but don't really know what to do with my seeder files. I definitely don't want to run seeder files in production, so I thought I would ignore them. I wouldn't want to accidently migrate and seed fake data into production!

Yet, I'm thinking seeders can be used in production with real data. Say I add a new column that must perform some calculation on the other table columns (for the sake of the example let us ignore that any field that can be calculated from other fields shouldn't exist in the database) and store a value. Or a new setting/flag. I think I could create a seeder to populate that field with the already existing production data. So now I can't ignore the seeder directory.

Should I decide on ignoring each file independently for every case? Can I declare somewhere that the seeder should only run in dev environment? What is the convention here?

Vic
  • 2,655
  • 3
  • 18
  • 28

1 Answers1

4

No. Seed files should be part of your repo. Of course you shouldn't run them in production, but a developer checking your code out should be able to migrate and seed their database with dummy data. They can't very well do that if you've gitignore-d the directory contents.

Martin Bean
  • 38,379
  • 25
  • 128
  • 201
  • So just to make sure, seed files are never used to seed real data like in my example above? Seed files are _only_ for dummy data? – Vic Jun 10 '15 at 23:09
  • 2
    There are cases where data would be seeded even in production. There are a lot of sites I have done where things like Country/State/Roles etc would be seeded on the initial launch to production. Obviously after the initial launch they aren't run again. And yes they are kept in the repo. – James Taylor Jun 11 '15 at 01:33
  • 1
    Well run the specific seed files, i.e. `php artisan db:seed --class=CountryTableSeeder` – Martin Bean Jun 11 '15 at 08:48
  • Awesome. Didn't know I could run a specific file. Thanks! – Vic Jun 11 '15 at 15:11