Changeset 1217
- Timestamp:
- 08/31/06 08:50:52 (2 years ago)
- Files:
-
- discussionplugin/0.9/tracdiscussion/db/db1.py (modified) (6 diffs)
- discussionplugin/0.9/tracdiscussion/db/db2.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
discussionplugin/0.9/tracdiscussion/db/db1.py
r1013 r1217 7 7 subject text, 8 8 description text 9 ) ;""",9 )""", 10 10 """CREATE TABLE topic ( 11 11 id integer PRIMARY KEY, … … 15 15 subject text, 16 16 body text 17 ) ;""",17 )""", 18 18 """CREATE TABLE message ( 19 19 id integer PRIMARY KEY, … … 24 24 author text, 25 25 body text 26 ) ;""",27 """INSERT INTO system (name, value) VALUES ('discussion_version', 1);""" ]26 )""", 27 """INSERT INTO system (name, value) VALUES ('discussion_version', '1')""" ] 28 28 29 29 # PostgreSQL statements … … 35 35 subject text, 36 36 description text 37 ) ;""",37 )""", 38 38 """CREATE TABLE topic ( 39 39 id serial PRIMARY KEY, … … 43 43 subject text, 44 44 body text 45 ) ;""",45 )""", 46 46 """CREATE TABLE message ( 47 47 id serial PRIMARY KEY, … … 52 52 author text, 53 53 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')""" ] 57 56 58 57 def do_upgrade(env, cursor): discussionplugin/0.9/tracdiscussion/db/db2.py
r1006 r1217 1 1 # Common statements 2 sql = ["""CREATE TABLE forum_group ( 2 pre_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 ( 3 14 id integer PRIMARY KEY, 4 15 name text, 5 16 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 19 post_sql = ["""DROP TABLE tmp_forum""", 20 """UPDATE system SET value = '2' WHERE name='discussion_version'"""] 10 21 11 22 # PostgreSQL statements 12 postgre_sql = ["""CREATE TABLE forum_group ( 23 pre_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 ( 13 35 id serial PRIMARY KEY, 14 36 name text, 15 37 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 )"""] 20 39 21 40 def do_upgrade(env, cursor): 22 41 if env.config.get('trac', 'database').startswith('postgres'): 23 for statement in p ostgre_sql:42 for statement in pre_postgre_sql: 24 43 cursor.execute(statement) 25 44 else: 26 for statement in sql:45 for statement in pre_sql: 27 46 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)
