source: peerreviewplugin/trunk/codereview/upgrades/db_peerreviewcomment_4.py

Last change on this file was 16451, checked in by Ryan J Ollos, 6 years ago

Fix indentation

File size: 1.6 KB
Line 
1from trac.db import Table, Column, Index, DatabaseManager
2
3
4def do_upgrade(env, ver, db_backend, db):
5    """
6
7    """
8    cursor = db.cursor()
9
10    realm = 'peerreviewcomment'
11
12    cursor.execute("CREATE TEMPORARY TABLE peerreviewcomment_old AS SELECT * FROM peerreviewcomment")
13    cursor.execute("DROP TABLE peerreviewcomment")
14
15    table_metadata = Table('peerreviewcomment', key=('comment_id', 'file_id', 'author'))[
16                              Column('comment_id', auto_increment=True, type='int'),
17                              Column('file_id', type='int'),
18                              Column('parent_id', type='int'),
19                              Column('line_num', type='int'),
20                              Column('author'),
21                              Column('comment'),
22                              Column('attachment_path'),
23                              Column('created', type='int'),
24                              Column('refs'),
25                              Column('type'),
26                              Column('status')]
27
28    env.log.info("Updating table for class %s" % realm)
29    for stmt in db_backend.to_sql(table_metadata):
30        env.log.debug(stmt)
31        cursor.execute(stmt)
32
33    cursor = db.cursor()
34
35    cursor.execute("INSERT INTO peerreviewcomment "
36                   "(comment_id,file_id,parent_id,line_num,author,comment,attachment_path,created,refs,type,status) "
37                   "SELECT comment_id,file_id,parent_id,line_num,author,comment,attachment_path,created,refs,type,status "
38                   "FROM peerreviewcomment_old")
39
40    cursor.execute("DROP TABLE peerreviewcomment_old")
Note: See TracBrowser for help on using the repository browser.