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

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

Fix indentation

File size: 1.7 KB
Line 
1from trac.db import Table, Column, Index, DatabaseManager
2
3
4def do_upgrade(env, ver, db_backend, db):
5    """Change 'created' from seconds to microseconds."""
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', 'file_id', 'author'))[
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
26    env.log.info("Updating table values for 'created' of class %s" % realm)
27    for stmt in db_backend.to_sql(table_metadata):
28        env.log.debug(stmt)
29        cursor.execute(stmt)
30
31    cursor = db.cursor()
32
33    cursor.execute("INSERT INTO peerreviewcomment "
34                   "(comment_id,file_id,parent_id,line_num,author,comment,attachment_path,created,refs,type,status) "
35                   "SELECT comment_id,file_id,parent_id,line_num,author,comment,attachment_path,created * 1000000,refs,type,status "
36                   "FROM peerreviewcomment_old")
37
38    cursor.execute("DROP TABLE peerreviewcomment_old")
Note: See TracBrowser for help on using the repository browser.