Package buildbot :: Package db :: Package schema :: Module v3
[frames] | no frames]

Source Code for Module buildbot.db.schema.v3

 1  from buildbot.db.schema import base 
 2   
3 -class Upgrader(base.Upgrader):
4 - def upgrade(self):
5 self.migrate_schedulers() 6 self.set_version()
7
8 - def migrate_schedulers(self):
9 cursor = self.conn.cursor() 10 # If this fails, there's no cleaning up to do 11 cursor.execute(""" 12 ALTER TABLE schedulers 13 RENAME TO schedulers_old 14 """) 15 16 try: 17 cursor.execute(""" 18 CREATE TABLE schedulers ( 19 `schedulerid` INTEGER PRIMARY KEY, -- joins to other tables 20 `name` VARCHAR(127) NOT NULL, -- the scheduler's name according to master.cfg 21 `class_name` VARCHAR(127) NOT NULL, -- the scheduler's class 22 `state` VARCHAR(1024) NOT NULL -- JSON-encoded state dictionary 23 ); 24 """) 25 except: 26 # Restore the original table 27 cursor.execute(""" 28 ALTER TABLE schedulers_old 29 RENAME TO schedulers 30 """) 31 raise 32 33 try: 34 cursor.execute(""" 35 CREATE UNIQUE INDEX `name_and_class` ON 36 schedulers (`name`, `class_name`) 37 """) 38 39 cursor.execute(""" 40 INSERT INTO schedulers (`schedulerid`, `name`, `state`, `class_name`) 41 SELECT `schedulerid`, `name`, `state`, '' FROM schedulers_old 42 """) 43 cursor.execute(""" 44 DROP TABLE schedulers_old 45 """) 46 except: 47 # Clean up the new table, and restore the original 48 cursor.execute(""" 49 DROP TABLE schedulers 50 """) 51 cursor.execute(""" 52 ALTER TABLE schedulers_old 53 RENAME TO schedulers 54 """) 55 raise
56
57 - def set_version(self):
58 c = self.conn.cursor() 59 c.execute("""UPDATE version set version = 3 where version = 2""")
60