1 from buildbot.db.schema import base
2 from buildbot.db.exceptions import DatabaseNotReadyError
3
8
10 cursor = self.conn.cursor()
11
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
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
49 cursor.execute("""
50 DROP TABLE schedulers
51 """)
52 cursor.execute("""
53 ALTER TABLE schedulers_old
54 RENAME TO schedulers
55 """)
56 raise
57
59 c = self.conn.cursor()
60 c.execute("""UPDATE version set version = 3 where version = 2""")
61