I actually want to get rid of the existing constraints in the database which I know sounds crazy but we are upgrading our application to a new framework which relies on the foreign key constraint names plus we're doing a bunch of cleanup and renaming of fields, tables etc.
I suppose a better way to frame the question is that given an existing database that needs to go through the following:
- Create all brand new foreign key constraints with names that work within the framework
- Tables will be renamed and/or massively restructured including renaming fields that are currently part of existing foreign key relationships
What is the best way to accomplish this?
My solutions thus far have been:
- Create a conversion script (in php) that will run DROP FOREIGN KEY for all of the constraints in the database. This has resulted in weird errors occurring during the later steps of the process when trying to ALTER TABLES and add in the new constraints. Also, the constraints were removed but I get errors if I try to DROP the keys themselves.
- Instead of using PHP and PDO, write the conversion script using straight SQL and use a CURSOR to DROP the constraints.
- Instead of dropping the constraints themselves, convert the tables to MyIsam and DROP the keys then convert back to Innodb before continuing with the rest of the conversion process.
- Create a brand new schema from scratch and then move the data from the old schema to the new.
I would like to know which of these approaches would be considered the most valid? Or if there is a better way of doing this?
UPDATE (this information was requested in the chat room so I thought I would add it here):
- The current schema has 68 tables, the new schema will be closer to 55.
- The largest table has just over 800,000 rows and in general our tables are in the tens of thousands.
- The entire database is roughly 240 MB but most of that is in a single table that stores a large text field. We'll be compressing this during the conversion.