1 def migrate_up(manager): 2 manager.execute_script(CLEAN_DATABASE) 3 manager.execute(ADD_HOST_QUEUE_DELETED_COLUMN) 4 manager.execute(DROP_DEFAULT) 5 6 def migrate_down(manager): 7 manager.execute(DROP_HOST_QUEUE_DELETED_COLUMN) 8 9 CLEAN_DATABASE = """DELETE FROM acl_groups_hosts 10 WHERE host_id IN 11 (SELECT id FROM hosts WHERE invalid = TRUE); 12 13 DELETE FROM ineligible_host_queues 14 WHERE host_id IN 15 (SELECT id FROM hosts WHERE invalid = TRUE); 16 17 UPDATE host_queue_entries 18 SET status = 'Abort' 19 WHERE host_id IN 20 (SELECT id FROM hosts WHERE invalid = TRUE) 21 AND active = TRUE; 22 23 UPDATE host_queue_entries 24 SET status = 'Aborted', complete = TRUE 25 WHERE host_id IN 26 (SELECT id FROM hosts WHERE invalid = TRUE) 27 AND active = FALSE AND complete = FALSE; 28 29 DELETE FROM hosts_labels 30 WHERE host_id IN 31 (SELECT id FROM hosts WHERE invalid = TRUE);""" 32 33 DROP_HOST_QUEUE_DELETED_COLUMN = """ALTER TABLE host_queue_entries 34 DROP COLUMN deleted""" 35 36 ADD_HOST_QUEUE_DELETED_COLUMN = """ALTER TABLE host_queue_entries 37 ADD COLUMN deleted BOOLEAN 38 NOT NULL DEFAULT FALSE""" 39 40 DROP_DEFAULT = """ALTER TABLE host_queue_entries 41 ALTER COLUMN deleted DROP DEFAULT""" 42