| 1 | sql = [ |
|---|
| 2 | #-- Add ticket_type to 'ticket', remove the unused 'url' column |
|---|
| 3 | """CREATE TEMPORARY TABLE ticket_old AS SELECT * FROM ticket;""", |
|---|
| 4 | """DROP TABLE ticket;""", |
|---|
| 5 | """CREATE TABLE ticket ( |
|---|
| 6 | id integer PRIMARY KEY, |
|---|
| 7 | type text, -- the nature of the ticket |
|---|
| 8 | time integer, -- the time it was created |
|---|
| 9 | changetime integer, |
|---|
| 10 | component text, |
|---|
| 11 | severity text, |
|---|
| 12 | priority text, |
|---|
| 13 | owner text, -- who is this ticket assigned to |
|---|
| 14 | reporter text, |
|---|
| 15 | cc text, -- email addresses to notify |
|---|
| 16 | version text, -- |
|---|
| 17 | milestone text, -- |
|---|
| 18 | status text, |
|---|
| 19 | resolution text, |
|---|
| 20 | summary text, -- one-line summary |
|---|
| 21 | description text, -- problem description (long) |
|---|
| 22 | keywords text |
|---|
| 23 | );""", |
|---|
| 24 | """INSERT INTO ticket(id, type, time, changetime, component, severity, priority, |
|---|
| 25 | owner, reporter, cc, version, milestone, status, resolution, |
|---|
| 26 | summary, description, keywords) |
|---|
| 27 | SELECT id, 'defect', time, changetime, component, severity, priority, owner, |
|---|
| 28 | reporter, cc, version, milestone, status, resolution, summary, |
|---|
| 29 | description, keywords FROM ticket_old |
|---|
| 30 | WHERE COALESCE(severity,'') <> 'enhancement';""", |
|---|
| 31 | """INSERT INTO ticket(id, type, time, changetime, component, severity, priority, |
|---|
| 32 | owner, reporter, cc, version, milestone, status, resolution, |
|---|
| 33 | summary, description, keywords) |
|---|
| 34 | SELECT id, 'enhancement', time, changetime, component, 'normal', priority, |
|---|
| 35 | owner, reporter, cc, version, milestone, status, resolution, summary, |
|---|
| 36 | description, keywords FROM ticket_old |
|---|
| 37 | WHERE severity = 'enhancement';""", |
|---|
| 38 | """INSERT INTO enum (type, name, value) VALUES ('ticket_type', 'defect', '1');""", |
|---|
| 39 | """INSERT INTO enum (type, name, value) VALUES ('ticket_type', 'enhancement', '2');""", |
|---|
| 40 | """INSERT INTO enum (type, name, value) VALUES ('ticket_type', 'task', '3');""", |
|---|
| 41 | """DELETE FROM enum WHERE type = 'severity' AND name = 'enhancement';""", |
|---|
| 42 | """DROP TABLE ticket_old;""", |
|---|
| 43 | ] |
|---|
| 44 | |
|---|
| 45 | def do_upgrade(env, ver, cursor): |
|---|
| 46 | for s in sql: |
|---|
| 47 | cursor.execute(s) |
|---|
| 48 | |
|---|
| 49 | # -- upgrade reports (involve a rename) |
|---|
| 50 | cursor.execute("SELECT id,sql FROM report") |
|---|
| 51 | reports = {} |
|---|
| 52 | for id, rsql in cursor: |
|---|
| 53 | reports[id] = rsql |
|---|
| 54 | for id, rsql in reports.items(): |
|---|
| 55 | parts = rsql.split('ORDER BY', 1) |
|---|
| 56 | ending = len(parts)>1 and 'ORDER BY'+parts[1] or '' |
|---|
| 57 | cursor.execute("UPDATE report SET sql=%s WHERE id=%s", |
|---|
| 58 | (parts[0].replace('severity,', |
|---|
| 59 | 't.type AS type, severity,') + ending, |
|---|
| 60 | id)) |
|---|