Question

This is more about checking my logic to see if i understand whether or not my idea of migration is the same as more experienced folk.

I have 2 databases, one with my current website stuff and one with my new development stuff. I now want to load all the current website database onto my new development database.

These databases have different schemas, different structures in terms of column names and a bit more decoupling in terms of data within the new development database tables.

To do this i am using php and sql, where by i'm calling specific tables using sql into multidimensional arrays to get all the relevant data needed for my new development database tables. checking to see if its repeat data and ordering it.

So now i have a multidimensional array that is full of data needed for my new database table which has been extracted from the old tables. I have renamed all the keys in the multidimensional array to match the names of the database. So technically i have a multidimensional array that is a copy of what i want to insert into my database.

Then i insert that multidimensional array into the new database and bobs your uncle a migration of a database?

Does this sound right and is there some suggested reading that you guys n girls might point me to?

Regards Mike

EDIT

By using multidimensional arrays to collect all the data that i want to put into my new database, wont i then be double handling the data and therefore use alot more resources from my migration script?

Was it helpful?

Solution 2

So I've researched about creating a migration script and I thought id explain to anyone else who has to do this a general outline in how to implement it. Bare in mind I'm only really using basic php no class's or functions, all procedural. I'm going to focus on one particular table and from that you can extrapolate for the whole database.

1) Create a php file specifically for collating the data of this one table (e.g table1.php)

2) Create all the sql statements you'll need to extract all relevant information for that particular table

3) With each sql statement create a loop and put all the data fetched from the sql statement into a array

4) Then create loop and an sql statement for inserting the data from the arrays you just populated into the new database. and if you want to check for repeat data just implement this check within this loop and sql statement.

5) Note you can add a timer and a counter for checking how long it took and amount of files transferred and or number of duplicates.

This may be obvious for most people, and might be considered wrong by others but my original plan on collating the data in a "table equivalent multidimensional array" and then inserting that array into the table meant i was double handling data (i think). So i assumed it would more efficient doing it this way, and a lot more simple.

I hope this basic outline will help anyone considering doing the same thing for the first time, and if someone has thoughts on how to make this operation more effective please feel free to rip this explanation apart. As this is only what I've implemented myself through trail and error as i have no real experience in this its just what I've concocted myself.

Regards Mike

OTHER TIPS

I have never tried this before but I am pretty certain you can access 2 databases at the same time. That being said you can extract from DB1 do your checks, changes, etc then just insert into the new DB.

Here is a stack question that does connect to 2 db's

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top