mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 1 | import os |
| 2 | |
| 3 | required_tables = ('machines', 'jobs', 'patches', 'tests', 'test_attributes', |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 4 | 'iteration_result') |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 5 | |
| 6 | def migrate_up(manager): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 7 | manager.execute("SHOW TABLES") |
| 8 | tables = [row[0] for row in manager.cursor.fetchall()] |
| 9 | db_initialized = True |
| 10 | for table in required_tables: |
| 11 | if table not in tables: |
| 12 | db_initialized = False |
| 13 | break |
| 14 | if not db_initialized: |
| 15 | response = raw_input( |
| 16 | 'Your tko database does not appear to be initialized. Do ' |
| 17 | 'you want to recreate it (this will result in loss of any ' |
| 18 | 'existing data) (yes/No)? ') |
| 19 | if response != 'yes': |
| 20 | raise Exception('User has chosen to abort migration') |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 21 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 22 | manager.execute_script(CREATE_DB_SQL) |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 23 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 24 | manager.create_migrate_table() |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 25 | |
| 26 | |
mbligh | aa383b7 | 2008-03-12 20:11:56 +0000 | [diff] [blame] | 27 | def migrate_down(manager): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 28 | manager.execute_script(DROP_DB_SQL) |
mbligh | aa383b7 | 2008-03-12 20:11:56 +0000 | [diff] [blame] | 29 | |
| 30 | |
| 31 | DROP_DB_SQL = """\ |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 32 | -- drop all views (since they depend on some or all of the following tables) |
| 33 | DROP VIEW IF EXISTS test_view; |
| 34 | DROP VIEW IF EXISTS perf_view; |
| 35 | |
| 36 | DROP TABLE IF EXISTS brrd_sync; |
| 37 | DROP TABLE IF EXISTS iteration_result; |
| 38 | DROP TABLE IF EXISTS test_attributes; |
| 39 | DROP TABLE IF EXISTS tests; |
| 40 | DROP TABLE IF EXISTS patches; |
| 41 | DROP TABLE IF EXISTS jobs; |
| 42 | DROP TABLE IF EXISTS machines; |
| 43 | DROP TABLE IF EXISTS kernels; |
| 44 | DROP TABLE IF EXISTS status; |
mbligh | aa383b7 | 2008-03-12 20:11:56 +0000 | [diff] [blame] | 45 | """ |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 46 | |
mbligh | aa383b7 | 2008-03-12 20:11:56 +0000 | [diff] [blame] | 47 | |
| 48 | CREATE_DB_SQL = DROP_DB_SQL + """\ |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 49 | -- status key |
| 50 | CREATE TABLE status ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 51 | status_idx int(10) unsigned NOT NULL auto_increment PRIMARY KEY , -- numerical status |
| 52 | word VARCHAR(10) -- status word |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 53 | ) TYPE=InnoDB; |
| 54 | |
| 55 | -- kernel versions |
| 56 | CREATE TABLE kernels ( |
| 57 | kernel_idx int(10) unsigned NOT NULL auto_increment PRIMARY KEY, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 58 | kernel_hash VARCHAR(35), -- Hash of base + all patches |
| 59 | base VARCHAR(30), -- Base version without patches |
| 60 | printable VARCHAR(100) -- Full version with patches |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 61 | ) TYPE=InnoDB; |
| 62 | |
| 63 | -- machines/hosts table |
| 64 | CREATE TABLE machines ( |
| 65 | machine_idx int(10) unsigned NOT NULL auto_increment PRIMARY KEY, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 66 | hostname VARCHAR(100) unique KEY, -- hostname |
| 67 | machine_group VARCHAR(80), -- group name |
| 68 | owner VARCHAR(80) -- owner name |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 69 | ) TYPE=InnoDB; |
| 70 | |
| 71 | -- main jobs table |
| 72 | CREATE TABLE jobs ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 73 | job_idx int(10) unsigned NOT NULL auto_increment PRIMARY KEY, -- index number |
| 74 | tag VARCHAR(100) unique KEY, -- job key |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 75 | label VARCHAR(100), -- job label assigned by user |
| 76 | KEY (label), |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 77 | username VARCHAR(80), -- user name |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 78 | KEY (username), |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 79 | machine_idx INT(10) unsigned NOT NULL, -- reference to machine table |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 80 | KEY (machine_idx), |
| 81 | FOREIGN KEY (machine_idx) REFERENCES machines(machine_idx) ON DELETE CASCADE |
| 82 | ) TYPE=InnoDB; |
| 83 | |
| 84 | -- One entry per patch used, anywhere |
| 85 | CREATE TABLE patches ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 86 | kernel_idx INT(10) unsigned NOT NULL, -- index number |
| 87 | name VARCHAR(80), -- short name |
| 88 | url VARCHAR(300), -- full URL |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 89 | hash VARCHAR(35), |
| 90 | KEY (kernel_idx), |
| 91 | FOREIGN KEY (kernel_idx) REFERENCES kernels(kernel_idx) ON DELETE CASCADE |
| 92 | ) TYPE=InnoDB; |
| 93 | |
| 94 | -- test functional results |
| 95 | CREATE TABLE tests ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 96 | test_idx int(10) unsigned NOT NULL auto_increment PRIMARY KEY, -- index number |
| 97 | job_idx INTEGER, -- ref to job table |
| 98 | test VARCHAR(30), -- name of test |
| 99 | subdir VARCHAR(60), -- subdirectory name |
| 100 | kernel_idx INT(10) unsigned NOT NULL, -- kernel test was AGAINST |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 101 | KEY (kernel_idx), |
| 102 | FOREIGN KEY (kernel_idx) REFERENCES kernels(kernel_idx) ON DELETE CASCADE, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 103 | status int(10) unsigned NOT NULL, -- test status |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 104 | KEY (status), |
| 105 | FOREIGN KEY (status) REFERENCES status(status_idx) ON DELETE CASCADE, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 106 | reason VARCHAR(100), -- reason for test status |
| 107 | machine_idx INT(10) unsigned NOT NULL, -- reference to machine table |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 108 | KEY (machine_idx), |
| 109 | FOREIGN KEY (machine_idx) REFERENCES machines(machine_idx) ON DELETE CASCADE, |
| 110 | invalid BOOL NOT NULL |
| 111 | ) TYPE=InnoDB; |
| 112 | |
| 113 | -- test attributes (key value pairs at a test level) |
| 114 | CREATE TABLE test_attributes ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 115 | test_idx int(10) unsigned NOT NULL, -- ref to test table |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 116 | FOREIGN KEY (test_idx) REFERENCES tests(test_idx) ON DELETE CASCADE, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 117 | attribute VARCHAR(30), -- attribute name (e.g. 'version') |
| 118 | value VARCHAR(100), -- attribute value |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 119 | KEY `test_idx` (`test_idx`) |
| 120 | ) TYPE=InnoDB; |
| 121 | |
| 122 | -- test performance results |
| 123 | CREATE TABLE iteration_result( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 124 | test_idx int(10) unsigned NOT NULL, -- ref to test table |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 125 | FOREIGN KEY (test_idx) REFERENCES tests(test_idx) ON DELETE CASCADE, |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 126 | iteration INTEGER, -- integer |
| 127 | attribute VARCHAR(30), -- attribute name (e.g. 'throughput') |
| 128 | value FLOAT, -- attribute value (eg 700.1) |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 129 | KEY `test_idx` (`test_idx`) |
| 130 | ) TYPE=InnoDB; |
| 131 | |
| 132 | -- BRRD syncronization |
| 133 | CREATE TABLE brrd_sync ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 134 | test_idx int(10) unsigned NOT NULL, -- ref to test table |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 135 | FOREIGN KEY (test_idx) REFERENCES tests(test_idx) ON DELETE CASCADE |
| 136 | ) TYPE=InnoDB; |
| 137 | |
| 138 | -- test_view (to make life easier for people trying to mine data) |
| 139 | CREATE VIEW test_view AS |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 140 | SELECT tests.test_idx, |
| 141 | tests.job_idx, |
| 142 | tests.test, |
| 143 | tests.subdir, |
| 144 | tests.kernel_idx, |
| 145 | tests.status, |
| 146 | tests.reason, |
| 147 | tests.machine_idx, |
| 148 | jobs.tag AS job_tag, |
| 149 | jobs.label AS job_label, |
| 150 | jobs.username AS job_username, |
| 151 | machines.hostname AS machine_hostname, |
| 152 | machines.machine_group, |
| 153 | machines.owner AS machine_owner, |
| 154 | kernels.kernel_hash, |
| 155 | kernels.base AS kernel_base, |
| 156 | kernels.printable AS kernel_printable, |
| 157 | status.word AS status_word |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 158 | FROM tests |
| 159 | INNER JOIN jobs ON jobs.job_idx = tests.job_idx |
| 160 | INNER JOIN machines ON machines.machine_idx = jobs.machine_idx |
| 161 | INNER JOIN kernels ON kernels.kernel_idx = tests.kernel_idx |
| 162 | INNER JOIN status ON status.status_idx = tests.status; |
| 163 | |
| 164 | -- perf_view (to make life easier for people trying to mine performance data) |
| 165 | CREATE VIEW perf_view AS |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 166 | SELECT tests.test_idx, |
| 167 | tests.job_idx, |
| 168 | tests.test, |
| 169 | tests.subdir, |
| 170 | tests.kernel_idx, |
| 171 | tests.status, |
| 172 | tests.reason, |
| 173 | tests.machine_idx, |
| 174 | jobs.tag AS job_tag, |
| 175 | jobs.label AS job_label, |
| 176 | jobs.username AS job_username, |
| 177 | machines.hostname AS machine_hostname, |
| 178 | machines.machine_group, |
| 179 | machines.owner AS machine_owner, |
| 180 | kernels.kernel_hash, |
| 181 | kernels.base AS kernel_base, |
| 182 | kernels.printable AS kernel_printable, |
| 183 | status.word AS status_word, |
| 184 | iteration_result.iteration, |
| 185 | iteration_result.attribute AS iteration_key, |
| 186 | iteration_result.value AS iteration_value |
mbligh | 5456c2b | 2008-02-15 18:42:55 +0000 | [diff] [blame] | 187 | FROM tests |
| 188 | INNER JOIN jobs ON jobs.job_idx = tests.job_idx |
| 189 | INNER JOIN machines ON machines.machine_idx = jobs.machine_idx |
| 190 | INNER JOIN kernels ON kernels.kernel_idx = tests.kernel_idx |
| 191 | INNER JOIN status ON status.status_idx = tests.status |
| 192 | INNER JOIN iteration_result ON iteration_result.test_idx = tests.kernel_idx; |
| 193 | |
| 194 | INSERT INTO status (word) |
| 195 | VALUES ('NOSTATUS'), ('ERROR'), ('ABORT'), ('FAIL'), ('WARN'), ('GOOD'), ('ALERT'); |
| 196 | """ |