I have one migration that has different tables in it. Suppose you have a User and Profile table. So I’m writing this in the same migration. So what are the advantages and disadvantages of this?
I know the table will be depending on each other. So it can have a problem with rollback and all. But I want to know more thoughts about it
Please share any thoughts you have. Should we avoid this?
What are the best practices?
It should work fine to do so but you need to put them in correct order. Create users table before profiles table.
What you lose is the ability to rollback just the profiles without also rolling back users.
You might even have to use up/down instead of change, because the order of creation is usually reversed when deleting…
I do this for join tables, I group them inside one migration, but there is no interaction between tables.
But isn’t it hard to maintain and having a separate migration is easier to maintain?
Also what if there are more than two tables and they have relations. Is it still good to have tables like this?
What about foreign keys? Every time we rollback a table related to foreign keys, you have to first delete all foreign dependencies
I prefer to have one migration per entity table, but it’s personal. You might prefer the other way.