-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add referenced schema to foreign key constraints (#1252)
Also refactor tests.
- Loading branch information
Showing
8 changed files
with
1,015 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
tests/artifacts/xdmod/unit/etl/db-model/foreign-key-constraint/alter-table.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{ | ||
"Alter ON DELETE from NO ACTION to CASCADE": [ | ||
{ | ||
"table_definition": { | ||
"name": "test_db_model", | ||
"engine": "InnoDB", | ||
"charset": "latin1", | ||
"collation": "latin1_swedish_ci", | ||
"comment": "Events on an instance", | ||
"columns": [ | ||
{ | ||
"name": "event_id", | ||
"type": "bigint(20) unsigned", | ||
"nullable": false, | ||
"extra": "auto_increment", | ||
"comment": "Generated during intermediate ingest" | ||
}, | ||
{ | ||
"name": "col1", | ||
"type": "varchar(64)", | ||
"charset": "latin1", | ||
"collation": "latin1_swedish_ci", | ||
"nullable": false, | ||
"default": "mydefault" | ||
}, | ||
{ | ||
"name": "col2", | ||
"type": "varchar(64)", | ||
"charset": "utf8", | ||
"collation": "utf8_unicode_ci", | ||
"nullable": false, | ||
"default": "mydefault" | ||
}, | ||
{ | ||
"name": "event_time", | ||
"type": "timestamp", | ||
"nullable": false, | ||
"default": "CURRENT_TIMESTAMP" | ||
}, | ||
{ | ||
"name": "instance_id", | ||
"type": "int(11) unsigned", | ||
"nullable": true, | ||
"default": 10 | ||
}, | ||
{ | ||
"name": "inferred", | ||
"type": "int(1) unsigned", | ||
"nullable": true, | ||
"default": 0, | ||
"comment": "Not explicitly provided by source but inferred from other data" | ||
} | ||
], | ||
"indexes": [ | ||
{ | ||
"name": "fk_col", | ||
"columns": [ | ||
"col1" | ||
], | ||
"type": "BTREE", | ||
"is_unique": false | ||
}, | ||
{ | ||
"name": "fk_instance", | ||
"columns": [ | ||
"instance_id", | ||
"inferred" | ||
], | ||
"type": "BTREE", | ||
"is_unique": true | ||
} | ||
], | ||
"foreign_key_constraints": [ | ||
{ | ||
"name": "con_col1", | ||
"columns": [ | ||
"col1" | ||
], | ||
"referenced_table": "db_test_model2", | ||
"referenced_columns": [ | ||
"col3" | ||
], | ||
"on_delete": "CASCADE", | ||
"on_update": "NO ACTION" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"columns": [ | ||
"instance_id" | ||
], | ||
"referenced_table": "other_table", | ||
"referenced_columns": [ | ||
"other_column" | ||
], | ||
"on_delete": "NO ACTION" | ||
}, | ||
{ | ||
"columns": [ | ||
"instance_id" | ||
], | ||
"referenced_table": "other_table", | ||
"referenced_columns": [ | ||
"other_column" | ||
], | ||
"on_delete": "CASCADE" | ||
}, | ||
[ | ||
"ALTER TABLE `test_db_model`\nDROP FOREIGN KEY `fk_instance_id`;", | ||
"ALTER TABLE `test_db_model`\nADD CONSTRAINT `fk_instance_id` FOREIGN KEY (`instance_id`) REFERENCES `other_table` (`other_column`) ON DELETE CASCADE;" | ||
] | ||
] | ||
} |
105 changes: 105 additions & 0 deletions
105
tests/artifacts/xdmod/unit/etl/db-model/foreign-key-constraint/create-table.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"Table with simplest foreign key constraint": [ | ||
{ | ||
"table_definition": { | ||
"name": "test", | ||
"engine": "InnoDB", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "int(11)", | ||
"nullable": false, | ||
"extra": "auto_increment" | ||
}, | ||
{ | ||
"name": "other_id", | ||
"type": "int(11)", | ||
"nullable": false | ||
} | ||
], | ||
"indexes": [ | ||
{ | ||
"name": "PRIMARY", | ||
"columns": [ | ||
"id" | ||
] | ||
}, | ||
{ | ||
"name": "idx_other_id", | ||
"columns": [ | ||
"other_id" | ||
] | ||
} | ||
], | ||
"foreign_key_constraints": [ | ||
{ | ||
"name": "fk_other", | ||
"columns": [ | ||
"other_id" | ||
], | ||
"referenced_table": "other", | ||
"referenced_columns": [ | ||
"id" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
[ | ||
"CREATE TABLE IF NOT EXISTS `test` (\n `id` int(11) NOT NULL auto_increment,\n `other_id` int(11) NOT NULL,\n PRIMARY KEY (`id`),\n INDEX `idx_other_id` (`other_id`),\n CONSTRAINT `fk_other` FOREIGN KEY (`other_id`) REFERENCES `other` (`id`)\n) ENGINE = innodb;" | ||
] | ||
], | ||
"Table with complex foreign key constraint": [ | ||
{ | ||
"table_definition": { | ||
"name": "test", | ||
"engine": "InnoDB", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "int(11)", | ||
"nullable": false, | ||
"extra": "auto_increment" | ||
}, | ||
{ | ||
"name": "other_id", | ||
"type": "int(11)", | ||
"nullable": false | ||
} | ||
], | ||
"indexes": [ | ||
{ | ||
"name": "PRIMARY", | ||
"columns": [ | ||
"id" | ||
] | ||
}, | ||
{ | ||
"name": "idx_other_id", | ||
"columns": [ | ||
"other_id" | ||
] | ||
} | ||
], | ||
"foreign_key_constraints": [ | ||
{ | ||
"name": "fk_other", | ||
"columns": [ | ||
"other_id" | ||
], | ||
"referenced_schema": "mod_other", | ||
"referenced_table": "other", | ||
"referenced_columns": [ | ||
"id" | ||
], | ||
"on_delete": "SET NULL", | ||
"on_update": "CASCADE" | ||
} | ||
] | ||
} | ||
}, | ||
[ | ||
"CREATE TABLE IF NOT EXISTS `test` (\n `id` int(11) NOT NULL auto_increment,\n `other_id` int(11) NOT NULL,\n PRIMARY KEY (`id`),\n INDEX `idx_other_id` (`other_id`),\n CONSTRAINT `fk_other` FOREIGN KEY (`other_id`) REFERENCES `mod_other`.`other` (`id`) ON DELETE SET NULL ON UPDATE CASCADE\n) ENGINE = innodb;" | ||
] | ||
] | ||
} |
Oops, something went wrong.