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