I have basically MySQL dump from a WordPress database with some data. The whole dump is about 20MB and roughly 500 queries, so it doesn’t take forever to load, but it’s not super fast either.
I need ot use that database in my other application, and to do that, I have to change the schema, i.e. rename tables, columns, drop some columns, drop tables, create new tables and import data into them, etc.
In reality, I’m going to alter almost every single column. The question is, how should I write a script like that?
I’d like to be able to have one script that I can execute on a recent dump, that will convert the database to a required form. Which means that if I start typing ALTER TABLE queries and then executing them, I’m going to have to re-import the database every time I want to test the whole script, which doesn’t seem very effective to me. Is there any better way to do this?
Can I somehow run a bunch of queries, look at what they did, and then hit a button to move the database back to it’s original state?
I’m not 100% certain I understand your question, but I think you might be looking for
This would allow you to keep a “canonical” version of the old database untouched. Your ALTER TABLE statements would execute against the new tables.
Apart from the ability to run your whole script as a single transaction, there’s no simple sub-millisecond UNDO for these kinds of schema changes.
Having said all that, if a developer came to me and said “I’m going to routinely alter almost every single column”, I’d look at that as a big red flag, billowing in the wind.