Wow. crowded train. and database migration with scripts.

The train home is uber crowded. I still managed to get a seat.

today I have been writing a script that will migrate a database from one system to another – I have to traverse every table and sort the fields into the correct fields in the new table in the new database. I was thinking about different ways to do it – we need all the user accounts, passwords, user details, like address, phone # etc, along with their orders (from a seperate table) all the products and the categories too.

Im doing it with arrays of data – one class to setup and retrieve stuff from the database – and another to put it in to the new database (I was going to use one class for this, and I still might, ive not got as far as trying to put the data in yet.)

some of the tables are pretty strait forward =) just dumpin the fields and their data into an array where the indexes (keys) are the field name, and the data is the data. the array is named after the table.

others are a little more complicated – they have serialised data — though its only one thing thats serialised. that data has to go into an array where the index (key) is a value from the field ‘vars’ and the data is from a field called content. and I have had to check it for a regexp and remove all instances of that regexp. fair enough. I now have all the data for a customer – login details, order history, address, etc in three arrays. all I need to do is to figure out where the data is meant to go and change the indexes (keys) to the proper field names in the new database and dump it in.

all of that inside a while loop that goes through the whole table and returns the distinct value for user id.

that way I can run the script and it will go through the old databse, populate the arrays, change the index values and dump it to the new database.

once thats done I have all the user data (which will be different as the site im taking it from is still live and people are still signing up and ordering, hence the script)

then I have to do the same thing for the orders (the data for the users concerning orders is just an order id) – then the client has all their orders and the statuese of all their orders =).

then its on to products (but by that time I will have a few classes made and it should be pretty easy). once the script is wirking I need to populate the new database and test that everything works, and debug stuff that will no doubt come up. once all that is done I get to switch off their live site,  empty my test database and populate it properly, then switch on the new site.

=|

Leave a Reply