1ADD_FOREIGN_KEYS = """ 2ALTER TABLE tko_test_labels_tests DROP FOREIGN KEY tests_labels_tests_ibfk_1; 3ALTER TABLE tko_test_labels_tests ADD CONSTRAINT tests_labels_tests_ibfk_1 4 FOREIGN KEY (testlabel_id) REFERENCES tko_test_labels (id) 5 ON DELETE CASCADE; 6 7ALTER TABLE tko_test_labels_tests DROP FOREIGN KEY tests_labels_tests_ibfk_2; 8ALTER TABLE tko_test_labels_tests ADD CONSTRAINT tests_labels_tests_ibfk_2 9 FOREIGN KEY (test_id) REFERENCES tko_tests (test_idx) ON DELETE CASCADE; 10""" 11 12DROP_FOREIGN_KEYS = """ 13ALTER TABLE tko_test_labels_tests DROP FOREIGN KEY tests_labels_tests_ibfk_1; 14ALTER TABLE tko_test_labels_tests ADD CONSTRAINT tests_labels_tests_ibfk_1 15 FOREIGN KEY (testlabel_id) REFERENCES tko_test_labels (id); 16 17ALTER TABLE tko_test_labels_tests DROP FOREIGN KEY tests_labels_tests_ibfk_2; 18ALTER TABLE tko_test_labels_tests ADD CONSTRAINT tests_labels_tests_ibfk_2 19 FOREIGN KEY (test_id) REFERENCES tko_tests (test_idx); 20""" 21 22def migrate_up(mgr): 23 mgr.execute_script(ADD_FOREIGN_KEYS) 24 25def migrate_down(mgr): 26 mgr.execute_script(DROP_FOREIGN_KEYS) 27