Welcome Guest, Not a member yet? Register   Sign In
dbutil restore from backup problem (order of tables)

[eluser]Jaffer Haider[/eluser]
Hey guys,

I'm using the internal dbutil ($this->load->dbutil()) to backup a database. Backup works fine, but when I run the .sql file to restore the database, I run into a problem because the tables are sorted alphabetically, and not by their foreign key constraints.

I've used phpMyAdmin's import feature, as well as simply pasting in the SQL script into the SQL tab of phpMyAdmin (after creating an empty database).

I don't see any topic in the forum related to this. Hasn't anyone run into this problem? What's a common workaround for this?


[eluser]Jaffer Haider[/eluser]
Guys? No one?

CI doesn't have any visibility on possible constraints, so you have to give the order of your tables manually by passing it as a parameter:
$tables = array('table1', 'table2', 'table3');
$this->dbutil->backup( array('tables' => $tables) );
If you don't do this, you'll get the tables in the order provided by the 'SHOW TABLES' SQL command, which is probably platform specific.

[eluser]Jaffer Haider[/eluser]
Hmm, I was hoping to avoid giving the order of tables, since you need to maintain this list as the DB changes.


i think that you can disable foreign keys checking at the beginning of the script, and at the end...enable it again. Cause check the order to make the dump it's very hard.

If you have no portability requirement, that is possible. For MySQL's innodb:
// do your thing here

Theme © iAndrew 2016 - Forum software by © MyBB