• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1def migrate_up(manager):
2    manager.execute_script(CREATE_TABLE)
3    manager.execute("ALTER TABLE labels ADD `atomic_group_id` "
4                    "INT(11) DEFAULT NULL ")
5    manager.execute("ALTER TABLE labels ADD CONSTRAINT FOREIGN KEY "
6                    "(`atomic_group_id`) REFERENCES `atomic_groups` (`id`) "
7                    "ON DELETE NO ACTION")
8    manager.execute("ALTER TABLE host_queue_entries ADD `atomic_group_id` "
9                    "INT(11) DEFAULT NULL")
10    manager.execute("ALTER TABLE host_queue_entries ADD CONSTRAINT FOREIGN KEY "
11                    "(`atomic_group_id`) REFERENCES `atomic_groups` (`id`) "
12                    "ON DELETE NO ACTION")
13
14
15def migrate_down(manager):
16    manager.execute("ALTER TABLE host_queue_entries REMOVE `atomic_group_id`")
17    manager.execute("ALTER TABLE labels REMOVE `atomic_group_id`")
18    manager.execute("DROP TABLE IF EXISTS `atomic_groups`")
19
20
21CREATE_TABLE = """\
22CREATE TABLE `atomic_groups` (
23  `id` int(11) NOT NULL auto_increment,
24  `name` varchar(255) NOT NULL,
25  `description` longtext DEFAULT NULL,
26  `max_number_of_machines` int(11) NOT NULL,
27  PRIMARY KEY  (`id`),
28  UNIQUE KEY `name` (`name`)
29) ENGINE=InnoDB DEFAULT CHARSET=latin1
30"""
31