Package trac :: Package upgrades :: Module db13

Source Code for Module trac.upgrades.db13

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (C) 2005-2020 Edgewall Software 
 4  # All rights reserved. 
 5  # 
 6  # This software is licensed as described in the file COPYING, which 
 7  # you should have received as part of this distribution. The terms 
 8  # are also available at https://trac.edgewall.org/wiki/TracLicense. 
 9  # 
10  # This software consists of voluntary contributions made by many 
11  # individuals. For the exact contribution history, see the revision 
12  # history and logs, available at https://trac.edgewall.org/. 
13   
14  sql = [ 
15  #-- Add ticket_type to 'ticket', remove the unused 'url' column 
16  """CREATE TEMPORARY TABLE ticket_old AS SELECT * FROM ticket;""", 
17  """DROP TABLE ticket;""", 
18  """CREATE TABLE ticket ( 
19          id              integer PRIMARY KEY, 
20          type            text,           -- the nature of the ticket 
21          time            integer,        -- the time it was created 
22          changetime      integer, 
23          component       text, 
24          severity        text, 
25          priority        text, 
26          owner           text,           -- who is this ticket assigned to 
27          reporter        text, 
28          cc              text,           -- email addresses to notify 
29          version         text,           -- 
30          milestone       text,           -- 
31          status          text, 
32          resolution      text, 
33          summary         text,           -- one-line summary 
34          description     text,           -- problem description (long) 
35          keywords        text 
36  );""", 
37  """INSERT INTO ticket(id, type, time, changetime, component, severity, priority, 
38                     owner, reporter, cc, version, milestone, status, resolution, 
39                     summary, description, keywords) 
40    SELECT id, 'defect', time, changetime, component, severity, priority, owner, 
41           reporter, cc, version, milestone, status, resolution, summary, 
42           description, keywords FROM ticket_old 
43    WHERE COALESCE(severity,'') <> 'enhancement';""", 
44  """INSERT INTO ticket(id, type, time, changetime, component, severity, priority, 
45                     owner, reporter, cc, version, milestone, status, resolution, 
46                     summary, description, keywords) 
47    SELECT id, 'enhancement', time, changetime, component, 'normal', priority, 
48           owner, reporter, cc, version, milestone, status, resolution, summary, 
49           description, keywords FROM ticket_old 
50    WHERE severity = 'enhancement';""", 
51  """INSERT INTO enum (type, name, value) VALUES ('ticket_type', 'defect', '1');""", 
52  """INSERT INTO enum (type, name, value) VALUES ('ticket_type', 'enhancement', '2');""", 
53  """INSERT INTO enum (type, name, value) VALUES ('ticket_type', 'task', '3');""", 
54  """DELETE FROM enum WHERE type = 'severity' AND name = 'enhancement';""", 
55  """DROP TABLE ticket_old;""", 
56  ] 
57   
58 -def do_upgrade(env, ver, cursor):
59 for s in sql: 60 cursor.execute(s) 61 62 # -- upgrade reports (involve a rename) 63 cursor.execute("SELECT id,sql FROM report") 64 reports = {} 65 for id, rsql in cursor: 66 reports[id] = rsql 67 for id, rsql in reports.items(): 68 parts = rsql.split('ORDER BY', 1) 69 ending = len(parts)>1 and 'ORDER BY'+parts[1] or '' 70 cursor.execute("UPDATE report SET sql=%s WHERE id=%s", 71 (parts[0].replace('severity,', 72 't.type AS type, severity,') + ending, 73 id))
74