Changeset 1217

Show
Ignore:
Timestamp:
08/31/06 08:50:52 (2 years ago)
Author:
Blackhex
Message:

DiscussionPlugin:

Different database update behaviour.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • discussionplugin/0.9/tracdiscussion/db/db1.py

    r1013 r1217  
    77  subject text, 
    88  description text 
    9 );""", 
     9)""", 
    1010"""CREATE TABLE topic ( 
    1111  id integer PRIMARY KEY, 
     
    1515  subject text, 
    1616  body text 
    17 );""", 
     17)""", 
    1818"""CREATE TABLE message ( 
    1919  id integer PRIMARY KEY, 
     
    2424  author text, 
    2525  body text 
    26 );""", 
    27 """INSERT INTO system (name, value) VALUES ('discussion_version', 1);""" ] 
     26)""", 
     27"""INSERT INTO system (name, value) VALUES ('discussion_version', '1')""" ] 
    2828 
    2929# PostgreSQL statements 
     
    3535  subject text, 
    3636  description text 
    37 );""", 
     37)""", 
    3838"""CREATE TABLE topic ( 
    3939  id serial PRIMARY KEY, 
     
    4343  subject text, 
    4444  body text 
    45 );""", 
     45)""", 
    4646"""CREATE TABLE message ( 
    4747  id serial PRIMARY KEY, 
     
    5252  author text, 
    5353  body text 
    54 );""", 
    55 """INSERT INTO system (name, value) VALUES ('discussion_version', 1);""" ] 
    56  
     54)""", 
     55"""INSERT INTO system (name, value) VALUES ('discussion_version', '1')""" ] 
    5756 
    5857def do_upgrade(env, cursor): 
  • discussionplugin/0.9/tracdiscussion/db/db2.py

    r1006 r1217  
    11# Common statements 
    2 sql = ["""CREATE TABLE forum_group ( 
     2pre_sql = ["""ALTER TABLE forum RENAME TO tmp_forum""", 
     3"""CREATE TABLE forum ( 
     4  id integer PRIMARY KEY, 
     5  name text, 
     6  time integer, 
     7  author text, 
     8  moderators text, 
     9  subject text, 
     10  description text, 
     11  forum_group integer 
     12)""", 
     13"""CREATE TABLE forum_group ( 
    314  id integer PRIMARY KEY, 
    415  name text, 
    516  description text 
    6 );""", 
    7 """ALTER TABLE forum ADD COLUMN forum_group integer;""", 
    8 """ALTER TABLE forum ADD COLUMN author text;""", 
    9 """UPDATE system SET value = 2 WHERE name='discussion_version';"""] 
     17)"""] 
     18 
     19post_sql = ["""DROP TABLE tmp_forum""", 
     20"""UPDATE system SET value = '2' WHERE name='discussion_version'"""] 
    1021 
    1122# PostgreSQL statements 
    12 postgre_sql = ["""CREATE TABLE forum_group ( 
     23pre_postgre_sql = ["""ALTER TABLE forum RENAME TO tmp_forum""", 
     24"""CREATE TABLE forum ( 
     25  id serial PRIMARY KEY, 
     26  name text, 
     27  time integer, 
     28  author text, 
     29  moderators text, 
     30  subject text, 
     31  description text, 
     32  forum_group integer 
     33)""", 
     34"""CREATE TABLE forum_group ( 
    1335  id serial PRIMARY KEY, 
    1436  name text, 
    1537  description text 
    16 );""", 
    17 """ALTER TABLE forum ADD COLUMN forum_group integer;""", 
    18 """ALTER TABLE forum ADD COLUMN author text;""", 
    19 """UPDATE system SET value = 2 WHERE name='discussion_version';"""] 
     38)"""] 
    2039 
    2140def do_upgrade(env, cursor): 
    2241    if env.config.get('trac', 'database').startswith('postgres'): 
    23         for statement in postgre_sql: 
     42        for statement in pre_postgre_sql: 
    2443            cursor.execute(statement) 
    2544    else: 
    26         for statement in sql: 
     45        for statement in pre_sql: 
    2746            cursor.execute(statement) 
     47 
     48    columns = ('id', 'name', 'time', 'moderators', 'subject', 'description') 
     49    sql = "SELECT id, name, time, moderators, subject, description FROM" \ 
     50      " tmp_forum" 
     51    cursor.execute(sql) 
     52    forums = [] 
     53    for row in cursor: 
     54        row = dict(zip(columns, row)) 
     55        forums.append(row) 
     56 
     57    for forum in forums: 
     58        sql = "INSERT INTO forum (id, name, time, moderators, subject," \ 
     59          " description) VALUES (%s, %s, %s, %s, %s, %s)" 
     60        cursor.execute(sql, (forum['id'], forum['name'], forum['time'], 
     61          forum['moderators'], forum['subject'], forum['description'])) 
     62 
     63    for statement in post_sql: 
     64        cursor.execute(statement)