| 1 | from trac.db import Table, Column, Index, DatabaseManager |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | def do_upgrade(env, ver, db_backend, db): |
|---|
| 5 | """ |
|---|
| 6 | |
|---|
| 7 | """ |
|---|
| 8 | cursor = db.cursor() |
|---|
| 9 | |
|---|
| 10 | realm = 'peerreviewfile' |
|---|
| 11 | |
|---|
| 12 | cursor.execute("CREATE TEMPORARY TABLE peerreviewfile_old AS SELECT * FROM peer_review_file") |
|---|
| 13 | cursor.execute("DROP TABLE peer_review_file") |
|---|
| 14 | |
|---|
| 15 | table_metadata = Table('peerreviewfile', key='file_id')[ |
|---|
| 16 | Column('file_id', auto_increment=True, type='int'), |
|---|
| 17 | Column('review_id', type='int'), |
|---|
| 18 | Column('path'), |
|---|
| 19 | Column('line_start', type='int'), |
|---|
| 20 | Column('line_end', type='int'), |
|---|
| 21 | Column('repo'), |
|---|
| 22 | Column('revision'), |
|---|
| 23 | Column('changerevision'), |
|---|
| 24 | Column('hash'), |
|---|
| 25 | Column('status')] |
|---|
| 26 | |
|---|
| 27 | env.log.info("Updating table for class %s" % realm) |
|---|
| 28 | for stmt in db_backend.to_sql(table_metadata): |
|---|
| 29 | env.log.debug(stmt) |
|---|
| 30 | cursor.execute(stmt) |
|---|
| 31 | |
|---|
| 32 | cursor = db.cursor() |
|---|
| 33 | |
|---|
| 34 | cursor.execute("INSERT INTO peerreviewfile (file_id,review_id,path,line_start,line_end,repo,revision) " |
|---|
| 35 | "SELECT file_id,review_id,path,line_start,line_end,repo,revision FROM peerreviewfile_old") |
|---|
| 36 | |
|---|
| 37 | cursor.execute("DROP TABLE peerreviewfile_old") |
|---|