1 UP_SQL = """ 2 CREATE TABLE afe_shards ( 3 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY 4 ) ENGINE=innodb; 5 6 ALTER TABLE afe_jobs ADD COLUMN shard_id INT NULL; 7 ALTER TABLE afe_jobs ADD CONSTRAINT jobs_to_shard_ibfk 8 FOREIGN KEY (shard_id) REFERENCES afe_shards(id); 9 10 CREATE TABLE afe_shards_labels ( 11 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 12 shard_id INT NOT NULL, 13 label_id INT NOT NULL 14 ) ENGINE=InnoDB; 15 16 ALTER TABLE `afe_shards_labels` ADD CONSTRAINT shard_shard_id_fk 17 FOREIGN KEY (`shard_id`) REFERENCES `afe_shards` (`id`); 18 ALTER TABLE `afe_shards_labels` ADD CONSTRAINT shard_label_id_fk 19 FOREIGN KEY (`label_id`) REFERENCES `afe_labels` (`id`); 20 """ 21 22 DOWN_SQL = """ 23 ALTER TABLE afe_jobs DROP FOREIGN KEY jobs_to_shard_ibfk; 24 ALTER TABLE afe_jobs DROP COLUMN shard_id; 25 26 ALTER TABLE afe_shards_labels DROP FOREIGN KEY shard_label_id_fk; 27 ALTER TABLE afe_shards_labels DROP FOREIGN KEY shard_shard_id_fk; 28 DROP TABLE afe_shards_labels; 29 30 DROP TABLE afe_shards; 31 """ 32