qb
qb copied to clipboard
CreateAll() should order creations based on foreign keys
The current implementation create tables in the order they were added to the metadata. It obliges the user to add the tables in the right order, which can become cumbersome on big models.
Moreover, in case of cross-referenced tables, the table creation will fail altogether, when it should defer the foreign key constraints creation.
Hi @cdevienne. The table metadata should create tables first, then add foreign key constraints. Therefore, we wont't need any dependency order detection. I can change this. Here's an example;
CREATE TABLE `table1` (
-- blah blah
);
CREATE TABLE `table2`(
-- blah blah
);
-- blah blah
ALTER TABLE `table1`
ADD CONSTRAINT `fk_name`
FOREIGN KEY (`fk_table2_id`) REFERENCES `table2` (`t2`) ON DELETE CASCADE;