Changeset 1275

Show
Ignore:
Timestamp:
09/18/06 03:53:58 (2 years ago)
Author:
Blackhex
Message:

DiscussionPlugin:

Rollback to 0.9 database code.

Files:

Legend:

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

    r1253 r1275  
    1 from trac.db import Table, Column, Index, DatabaseManager 
     1# Commont SQL statements 
     2sql = ["""CREATE TABLE forum ( 
     3  id integer PRIMARY KEY, 
     4  name text, 
     5  time integer, 
     6  moderators text, 
     7  subject text, 
     8  description text 
     9);""", 
     10"""CREATE TABLE topic ( 
     11  id integer PRIMARY KEY, 
     12  forum integer, 
     13  time integer, 
     14  author text, 
     15  subject text, 
     16  body text 
     17);""", 
     18"""CREATE TABLE message ( 
     19  id integer PRIMARY KEY, 
     20  forum integer, 
     21  topic integer, 
     22  replyto integer, 
     23  time integer, 
     24  author text, 
     25  body text 
     26);""", 
     27"""INSERT INTO system (name, value) VALUES ('discussion_version', 1);""" ] 
    228 
    3 tables = [ 
    4   Table('forum', key = 'id')[ 
    5     Column('id', type = 'integer', auto_increment = True), 
    6     Column('name'), 
    7     Column('time', type = 'integer'), 
    8     Column('moderators'), 
    9     Column('subject'), 
    10     Column('description') 
    11   ], 
    12   Table('topic', key = 'id')[ 
    13     Column('id', type = 'integer', auto_increment = True), 
    14     Column('forum', type = 'integer'), 
    15     Column('time', type = 'integer'), 
    16     Column('author'), 
    17     Column('subject'), 
    18     Column('body') 
    19   ], 
    20   Table('message', key = 'id')[ 
    21     Column('id', type = 'integer', auto_increment = True), 
    22     Column('forum', type = 'integer'), 
    23     Column('topic', type = 'integer'), 
    24     Column('replyto', type = 'integer'), 
    25     Column('time', type = 'integer'), 
    26     Column('author'), 
    27     Column('body') 
    28   ] 
    29 
     29# PostgreSQL statements 
     30postgre_sql = ["""CREATE TABLE forum ( 
     31  id serial PRIMARY KEY, 
     32  name text, 
     33  time integer, 
     34  moderators text, 
     35  subject text, 
     36  description text 
     37);""", 
     38"""CREATE TABLE topic ( 
     39  id serial PRIMARY KEY, 
     40  forum integer, 
     41  time integer, 
     42  author text, 
     43  subject text, 
     44  body text 
     45);""", 
     46"""CREATE TABLE message ( 
     47  id serial PRIMARY KEY, 
     48  forum integer, 
     49  topic integer, 
     50  replyto integer, 
     51  time integer, 
     52  author text, 
     53  body text 
     54);""", 
     55"""INSERT INTO system (name, value) VALUES ('discussion_version', 1);""" ] 
     56 
    3057 
    3158def do_upgrade(env, cursor): 
    32     db_connector, _ = DatabaseManager(env)._get_connector() 
    33  
    34     # Create tables 
    35     for table in tables
    36         for statement in db_connector.to_sql(table)
     59    if env.config.get('trac', 'database').startswith('postgres'): 
     60        for statement in postgre_sql: 
     61            cursor.execute(statement) 
     62    else
     63        for statement in sql
    3764            cursor.execute(statement) 
    3865 
    39     # Set database schema version. 
    40     cursor.execute("INSERT INTO system (name, value) VALUES" 
    41       " ('discussion_version', '1')") 
  • discussionplugin/0.9/tracdiscussion/db/db2.py

    r1253 r1275  
    1 from trac.db import Table, Column, Index, DatabaseManager 
     1# Common statements 
     2sql = ["""CREATE TABLE forum_group ( 
     3  id integer PRIMARY KEY, 
     4  name text, 
     5  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';"""] 
    210 
    3 tables = [ 
    4   Table('forum', key = 'id')[ 
    5     Column('id', type = 'integer', auto_increment = True), 
    6     Column('name'), 
    7     Column('time', type = 'integer'), 
    8     Column('forum_group', type = 'integer'), 
    9     Column('author'), 
    10     Column('moderators'), 
    11     Column('subject'), 
    12     Column('description') 
    13   ], 
    14   Table('forum_group', key = 'id')[ 
    15     Column('id', type = 'integer', auto_increment = True), 
    16     Column('name'), 
    17     Column('description') 
    18   ] 
    19 
     11# PostgreSQL statements 
     12postgre_sql = ["""CREATE TABLE forum_group ( 
     13  id serial PRIMARY KEY, 
     14  name text, 
     15  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';"""] 
    2020 
    2121def do_upgrade(env, cursor): 
    22     db_connector, _ = DatabaseManager(env)._get_connector() 
    23  
    24     # Backup old screenshot table. 
    25     cursor.execute("CREATE TEMPORARY TABLE forum_old AS SELECT * FROM forum") 
    26     cursor.execute("DROP TABLE forum") 
    27  
    28     # Create tables 
    29     for table in tables: 
    30         for statement in db_connector.to_sql(table): 
     22    if env.config.get('trac', 'database').startswith('postgres'): 
     23        for statement in postgre_sql: 
    3124            cursor.execute(statement) 
    32  
    33     # Copy old forums 
    34     cursor.execute("INSERT INTO forum (id, name, time, moderators, subject," \ 
    35       " description) SELECT id, name, time, moderators, subject, description" \ 
    36       " FROM forum_old") 
    37  
    38     # Set database schema version. 
    39     cursor.execute("DROP TABLE forum_old") 
    40     cursor.execute("UPDATE system SET value = '2' WHERE" \ 
    41       " name = 'discussion_version'") 
     25    else: 
     26        for statement in sql: 
     27            cursor.execute(statement)