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

Source Code for Module buildbot.db.schema.v3

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  from buildbot.db.schema import base 
17   
18 -class Upgrader(base.Upgrader):
19 - def upgrade(self):
20 self.migrate_schedulers() 21 self.set_version()
22
23 - def migrate_schedulers(self):
24 cursor = self.conn.cursor() 25 # If this fails, there's no cleaning up to do 26 cursor.execute(""" 27 ALTER TABLE schedulers 28 RENAME TO schedulers_old 29 """) 30 31 try: 32 cursor.execute(""" 33 CREATE TABLE schedulers ( 34 `schedulerid` INTEGER PRIMARY KEY, -- joins to other tables 35 `name` VARCHAR(127) NOT NULL, -- the scheduler's name according to master.cfg 36 `class_name` VARCHAR(127) NOT NULL, -- the scheduler's class 37 `state` VARCHAR(1024) NOT NULL -- JSON-encoded state dictionary 38 ); 39 """) 40 except: 41 # Restore the original table 42 cursor.execute(""" 43 ALTER TABLE schedulers_old 44 RENAME TO schedulers 45 """) 46 raise 47 48 try: 49 cursor.execute(""" 50 CREATE UNIQUE INDEX `name_and_class` ON 51 schedulers (`name`, `class_name`) 52 """) 53 54 cursor.execute(""" 55 INSERT INTO schedulers (`schedulerid`, `name`, `state`, `class_name`) 56 SELECT `schedulerid`, `name`, `state`, '' FROM schedulers_old 57 """) 58 cursor.execute(""" 59 DROP TABLE schedulers_old 60 """) 61 except: 62 # Clean up the new table, and restore the original 63 cursor.execute(""" 64 DROP TABLE schedulers 65 """) 66 cursor.execute(""" 67 ALTER TABLE schedulers_old 68 RENAME TO schedulers 69 """) 70 raise
71
72 - def set_version(self):
73 c = self.conn.cursor() 74 c.execute("""UPDATE version set version = 3 where version = 2""")
75