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

Source Code for Module buildbot.db.schema.v4

  1  from buildbot.db.schema import base 
  2   
3 -class Upgrader(base.Upgrader):
4 - def upgrade(self):
13
14 - def makeAutoincColumn(self, name):
15 if self.dbapiName == 'MySQLdb': 16 return "`%s` INTEGER PRIMARY KEY AUTO_INCREMENT" % name 17 elif self.dbapiName in ('sqlite3', 'pysqlite2.dbapi2'): 18 return "`%s` INTEGER PRIMARY KEY AUTOINCREMENT" % name 19 raise ValueError("Unsupported dbapi: %s" % self.dbapiName)
20
21 - def migrate_table(self, table_name, schema):
22 old_name = "%s_old" % table_name 23 cursor = self.conn.cursor() 24 # If this fails, there's no cleaning up to do 25 cursor.execute(""" 26 ALTER TABLE %(table_name)s 27 RENAME TO %(old_name)s 28 """ % locals()) 29 30 try: 31 cursor.execute(schema) 32 except: 33 # Restore the original table 34 cursor.execute(""" 35 ALTER TABLE %(old_name)s 36 RENAME TO %(table_name)s 37 """ % locals()) 38 raise 39 40 try: 41 cursor.execute(""" 42 INSERT INTO %(table_name)s 43 SELECT * FROM %(old_name)s 44 """ % locals()) 45 cursor.execute(""" 46 DROP TABLE %(old_name)s 47 """ % locals()) 48 except: 49 # Clean up the new table, and restore the original 50 cursor.execute(""" 51 DROP TABLE %(table_name)s 52 """ % locals()) 53 cursor.execute(""" 54 ALTER TABLE %(old_name)s 55 RENAME TO %(table_name)s 56 """ % locals()) 57 raise
58
59 - def set_version(self):
60 c = self.conn.cursor() 61 c.execute("""UPDATE version set version = 4 where version = 3""")
62
63 - def migrate_schedulers(self):
64 schedulerid_col = self.makeAutoincColumn('schedulerid') 65 schema = """ 66 CREATE TABLE schedulers ( 67 %(schedulerid_col)s, -- joins to other tables 68 `name` VARCHAR(100) NOT NULL, -- the scheduler's name according to master.cfg 69 `class_name` VARCHAR(100) NOT NULL, -- the scheduler's class 70 `state` VARCHAR(1024) NOT NULL -- JSON-encoded state dictionary 71 ); 72 """ % locals() 73 self.migrate_table('schedulers', schema) 74 75 # Fix up indices 76 cursor = self.conn.cursor() 77 cursor.execute(""" 78 CREATE UNIQUE INDEX `name_and_class` ON 79 schedulers (`name`, `class_name`) 80 """)
81
82 - def migrate_builds(self):
83 buildid_col = self.makeAutoincColumn('id') 84 schema = """ 85 CREATE TABLE builds ( 86 %(buildid_col)s, 87 `number` INTEGER NOT NULL, -- BuilderStatus.getBuild(number) 88 -- 'number' is scoped to both the local buildmaster and the buildername 89 `brid` INTEGER NOT NULL, -- matches buildrequests.id 90 `start_time` INTEGER NOT NULL, 91 `finish_time` INTEGER 92 ); 93 """ % locals() 94 self.migrate_table('builds', schema)
95
96 - def migrate_changes(self):
97 changeid_col = self.makeAutoincColumn('changeid') 98 schema = """ 99 CREATE TABLE changes ( 100 %(changeid_col)s, -- also serves as 'change number' 101 `author` VARCHAR(1024) NOT NULL, 102 `comments` VARCHAR(1024) NOT NULL, -- too short? 103 `is_dir` SMALLINT NOT NULL, -- old, for CVS 104 `branch` VARCHAR(1024) NULL, 105 `revision` VARCHAR(256), -- CVS uses NULL. too short for darcs? 106 `revlink` VARCHAR(256) NULL, 107 `when_timestamp` INTEGER NOT NULL, -- copied from incoming Change 108 `category` VARCHAR(256) NULL, 109 110 -- repository specifies, along with revision and branch, the 111 -- source tree in which this change was detected. 112 `repository` TEXT NOT NULL default '', 113 114 -- project names the project this source code represents. It is used 115 -- later to filter changes 116 `project` TEXT NOT NULL default '' 117 ); 118 """ % locals() 119 self.migrate_table('changes', schema) 120 121 # Drop changes_nextid columnt 122 cursor = self.conn.cursor() 123 cursor.execute("DROP TABLE changes_nextid")
124
125 - def migrate_buildrequests(self):
126 buildrequestid_col = self.makeAutoincColumn('id') 127 schema = """ 128 CREATE TABLE buildrequests ( 129 %(buildrequestid_col)s, 130 131 -- every BuildRequest has a BuildSet 132 -- the sourcestampid and reason live in the BuildSet 133 `buildsetid` INTEGER NOT NULL, 134 135 `buildername` VARCHAR(256) NOT NULL, 136 137 `priority` INTEGER NOT NULL default 0, 138 139 -- claimed_at is the time at which a master most recently asserted that 140 -- it is responsible for running the build: this will be updated 141 -- periodically to maintain the claim 142 `claimed_at` INTEGER default 0, 143 144 -- claimed_by indicates which buildmaster has claimed this request. The 145 -- 'name' contains hostname/basedir, and will be the same for subsequent 146 -- runs of any given buildmaster. The 'incarnation' contains bootime/pid, 147 -- and will be different for subsequent runs. This allows each buildmaster 148 -- to distinguish their current claims, their old claims, and the claims 149 -- of other buildmasters, to treat them each appropriately. 150 `claimed_by_name` VARCHAR(256) default NULL, 151 `claimed_by_incarnation` VARCHAR(256) default NULL, 152 153 `complete` INTEGER default 0, -- complete=0 means 'pending' 154 155 -- results is only valid when complete==1 156 `results` SMALLINT, -- 0=SUCCESS,1=WARNINGS,etc, from status/builder.py 157 158 `submitted_at` INTEGER NOT NULL, 159 160 `complete_at` INTEGER 161 ); 162 """ % locals() 163 self.migrate_table('buildrequests', schema)
164
165 - def migrate_buildsets(self):
166 buildsetsid_col = self.makeAutoincColumn('id') 167 schema = """ 168 CREATE TABLE buildsets ( 169 %(buildsetsid_col)s, 170 `external_idstring` VARCHAR(256), 171 `reason` VARCHAR(256), 172 `sourcestampid` INTEGER NOT NULL, 173 `submitted_at` INTEGER NOT NULL, 174 `complete` SMALLINT NOT NULL default 0, 175 `complete_at` INTEGER, 176 `results` SMALLINT -- 0=SUCCESS,2=FAILURE, from status/builder.py 177 -- results is NULL until complete==1 178 ); 179 """ % locals() 180 self.migrate_table("buildsets", schema)
181
182 - def migrate_patches(self):
183 patchesid_col = self.makeAutoincColumn('id') 184 schema = """ 185 CREATE TABLE patches ( 186 %(patchesid_col)s, 187 `patchlevel` INTEGER NOT NULL, 188 `patch_base64` TEXT NOT NULL, -- encoded bytestring 189 `subdir` TEXT -- usually NULL 190 ); 191 """ % locals() 192 self.migrate_table("patches", schema)
193
194 - def migrate_sourcestamps(self):
195 sourcestampsid_col = self.makeAutoincColumn('id') 196 schema = """ 197 CREATE TABLE sourcestamps ( 198 %(sourcestampsid_col)s, 199 `branch` VARCHAR(256) default NULL, 200 `revision` VARCHAR(256) default NULL, 201 `patchid` INTEGER default NULL, 202 `repository` TEXT not null default '', 203 `project` TEXT not null default '' 204 ); 205 """ % locals() 206 self.migrate_table("sourcestamps", schema)
207