3 ms·
Here's a trick to consider if you've got a truly large table to migrate, but with today's ActiveRecord-style abstractions it's harder to implement than if you w
by danudey 17y ago
Here's a trick to consider if you've got a truly large table to migrate, but with today's ActiveRecord-style abstractions it's harder to implement than if you were doing it yourself (like back in the PHP days).
1. Create a new table with the desired structure.
2. Modify your application to check the new table for data first, then the old table if the new table doesn't have the data.
3. Create a script that migrates data X rows at a time (in a transaction), populating the new table with the old data.
4. Once the new table is in place, replace the old table with new, and modify the application to check only that table.
Again, the setup required here can be developer-intensive and somewhat hackish, but if you have a truly colossal data store that'll take hours or days to ALTER TABLE, it's one way to work around it.