-
I feel like Laravels migration system could be improved. Especially for testing purposes. Wouldn't it make sense if we could separate migrations into schema changes and actual data changes? This would be super helpful for testing! In testing you mostly want to work with an empty db and a migration which do data changes might not work or even break your migrations. Sure you can do a We could fix that if migrations would have 2 sub folders, one called "schema" the other "data" and for testing only the schema migrations would be executed. Does this makes sense? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I don't think this is necessary. Generally speaking I try to avoid data changes in migrations due potential timeouts in production that you miss in CI because its a smaller dataset. Typically I'd write a migration to add a new column during a deployment, then outside of the deployment cycle we would populate the new column (run some SQL directly or it may be something that is eventually consistent via app-layer data changes/job). Then later we drop the old column. I think the solution you're seeking is stemming from how you're managing your seeder data, correct me if I'm wrong but it seems like you're storing data in your You should pull your data generation out into Seeders so that they can be updated as your models change more easily. Also if you have a bunch of old data a simple way to get started with this is to do something like;
|
Beta Was this translation helpful? Give feedback.
-
Data changes can be done with seeding or via one time command. |
Beta Was this translation helpful? Give feedback.
-
Here is an interesting package that does address the exact problem https://github.com/TimoKoerber/laravel-one-time-operations |
Beta Was this translation helpful? Give feedback.
-
I see your point. I sometimes work with codebases that have quite a few migration files. It would be nice to see at the first glance, where I can check the structure (the Another argument against having, let's say, two folders (one for creating and one for changing your table structure), is, that migration files should always be run in the same order and always all of them for consistency. Sure, Laravel could collect the files and sort them, but that would be an extra step. In the end, it comes down to Laravel being built on the principle that migrations are simple, consistent and repeatable. The way, they are now, they keep their promise. So, chance is not likely. |
Beta Was this translation helpful? Give feedback.
Here is an interesting package that does address the exact problem https://github.com/TimoKoerber/laravel-one-time-operations