1INDICES = ( 2 ('afe_host_queue_entries', 'active'), 3 ('afe_host_queue_entries', 'complete'), 4 ('afe_host_queue_entries', 'deleted'), 5 ('afe_host_queue_entries', 'aborted'), 6 ('afe_host_queue_entries', 'started_on'), 7 ('afe_host_queue_entries', 'finished_on'), 8 ('afe_host_queue_entries', 'job_id'), 9) 10 11def get_index_name(table, field): 12 """Formats the index name from a |table| and |field|.""" 13 return table + '_' + field 14 15 16def migrate_up(manager): 17 """Creates the indices.""" 18 for table, field in INDICES: 19 manager.execute('CREATE INDEX %s ON %s (%s)' % 20 (get_index_name(table, field), table, field)) 21 22 23def migrate_down(manager): 24 """Removes the indices.""" 25 for table, field in INDICES: 26 manager.execute('DROP INDEX %s ON %s' % 27 (get_index_name(table, field), table)) 28