Migrating database to new structure and converting data.
We are planning a major database restructure and instead of "Create" all the migrations are "Alter"-ing already existing tables.
For example:
There's table users that holds a column role.
After running migrations this column will be dropped and table "Roles" will be created with a hasOne relationship (just an example).
How should I approach converting the old data into the new structure as seamlessly as possible?
-
create a folder inside migrations called database refactoring or something
-
within that folder create to new folders called addition and altering
-
write a custom artisan command which does the following 3 in their respective order
- to first run all the addition of the new database tables and columns ( PHP artisan migrate has a path option where you can specify this)
- then I would write a script to all the data across
- I would drop the columns no longer necessary ( again use the path option for this using artisan migrate)
As usual backup db before attempting
I would do something along the line of
- Create a new database.
- Run all the migrations for the new structure in the new database
- Script the data from the old database into the new one.
Please or to participate in this conversation.