I have a MySQL table with around 5 million records, and I need to add a new value to an existing ENUM column. I've been using Sequelize to handle this change through my code, but as you can imagine, making this adjustment on such a large dataset is turning into a lengthy process, often leading to errors. I've also looked into other tools like Ghost, but they seem to be just as slow even for small changes. Does anyone have suggestions for how to streamline this process? I'm currently on MySQL 8.0.
5 Answers
Why not just use standard MySQL for this change? Seems like that might simplify things instead of using higher-level tools.
Have you considered using Percona's online schema change tool? It can make significant changes to your table structure without locking it for extensive periods.
You could just execute a simple SQL command to change the ENUM directly, which should be fast on MySQL 8.0. Remember, adding a new value to an ENUM is usually an instant operation. Just make sure to specify `ALGORITHM=INSTANT` in your command to avoid fallback to slower methods. Check the MySQL docs for this if you're unclear!
If you're trying to roll out new code simultaneously with the ENUM change, I suggest introducing the new ENUM value as nullable first. Then, execute a background job to set this value where needed. Once most records are updated, you can update your code to utilize and populate this new ENUM. Just check for any null values after the fact to recalculate and update them before finalizing the ENUM as non-nullable.
You might want to think about making your database backwards compatible and your code forwards compatible. Start by adding the new column as nullable. When your application writes, have it output to this new column. During reads, check the new column first; if it's null, fall back to the old column. Over time, as more data is migrated, you can eventually run a script to finalize the migration and remove the old schema—this can really help minimize downtime and errors.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically