source: peerreviewplugin/tags/0.12/3.1/codereview/upgrades/db_peerreviewcomment_6.py

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

Fix indentation

File size: 1.8 KB
Line 
1from trac.db import Table, Column, Index, DatabaseManager
2
3
4def do_upgrade(env, ver, db_backend, db):
5    """Change back primary key modified in version 4 to a sane default."""
6    cursor = db.cursor()
7
8    realm = 'peerreviewcomment'
9
10    cursor.execute("CREATE TEMPORARY TABLE peerreviewcomment_old AS SELECT * FROM peerreviewcomment")
11    cursor.execute("DROP TABLE peerreviewcomment")
12
13    table_metadata = Table('peerreviewcomment', key=('comment_id'))[
14                              Column('comment_id', auto_increment=True, type='int'),
15                              Column('file_id', type='int'),
16                              Column('parent_id', type='int'),
17                              Column('line_num', type='int'),
18                              Column('author'),
19                              Column('comment'),
20                              Column('attachment_path'),
21                              Column('created', type='int'),
22                              Column('refs'),
23                              Column('type'),
24                              Column('status'),
25                              Index(['file_id']),
26                              Index(['author'])]
27
28    env.log.info("Updating table values for 'created' of 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.