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