I need to migrate a database to an entirely new schema using groovy scripts, and I'm not sure where to start. Some of the table migrations will be almost one-to-one, apart from the new implementation of UUID's I have to use for all of the primary keys. For other tables, the data will have to be split up, and in some cases certain fields will have to be parsed into individual columns in the new database.
I believe I can do these things individually, but like I said I'm not sure where to start. Any helpful pointers, examples, links or advice would be welcome.
As an example, say in the old schema there is a person table with columns for name, job, etc. and personal info including address. In the new schema however there is an address table, so we need to migrate the address parts of person to an address entry and the rest to a person entry and connect the two with a UUID, via id and address_id respectfully. How do I do th开发者_高级运维at?
This isn't very complex but tedious. My suggested way to attack this:
- Create a very small database for your tests. H2 is your friend.
- Write small tests for each migration you need to do. This makes sure that changes tomorrow won't break today's work.
- Load the small database with test cases (where your migration didn't work). Write tests for that.
A test looks like so:
- Make a connection to the test database (or to two test databases, one in the old and one in the new format).
- Call the migration routine with the connection(s)
- Dump the result to a string
- Compare the string with what you expect
Start with the most simple migration that you can find and work your way up from there.
精彩评论