| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2016 Cinc |
|---|
| 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # This software is licensed as described in the file COPYING.txt, which |
|---|
| 7 | # you should have received as part of this distribution. |
|---|
| 8 | # |
|---|
| 9 | # Author: Cinc |
|---|
| 10 | # |
|---|
| 11 | from trac.db import Table, Column, DatabaseManager |
|---|
| 12 | |
|---|
| 13 | tables = [ |
|---|
| 14 | Table('peer_review', key='review_id')[ |
|---|
| 15 | Column('review_id', auto_increment=True, type='int'), |
|---|
| 16 | Column('owner'), |
|---|
| 17 | Column('status'), |
|---|
| 18 | Column('created', type='int'), |
|---|
| 19 | Column('name'), |
|---|
| 20 | Column('notes'), |
|---|
| 21 | Column('parent_id', type='int'), |
|---|
| 22 | Column('keywords'), |
|---|
| 23 | ], |
|---|
| 24 | Table('peer_reviewer', key=('review_id', 'reviewer'))[ |
|---|
| 25 | Column('review_id', type='int'), |
|---|
| 26 | Column('reviewer'), |
|---|
| 27 | Column('status', type='int'), |
|---|
| 28 | Column('vote', type='int'), |
|---|
| 29 | ], |
|---|
| 30 | Table('peer_review_file', key='file_id')[ |
|---|
| 31 | Column('file_id', auto_increment=True, type='int'), |
|---|
| 32 | Column('review_id', type='int'), |
|---|
| 33 | Column('path'), |
|---|
| 34 | Column('line_start', type='int'), |
|---|
| 35 | Column('line_end', type='int'), |
|---|
| 36 | Column('repo'), |
|---|
| 37 | Column('revision'), |
|---|
| 38 | ], |
|---|
| 39 | Table('peer_review_comment', key='comment_id')[ |
|---|
| 40 | Column('comment_id', auto_increment=True, type='int'), |
|---|
| 41 | Column('file_id', type='int'), |
|---|
| 42 | Column('parent_id', type='int'), |
|---|
| 43 | Column('line_num', type='int'), |
|---|
| 44 | Column('author'), |
|---|
| 45 | Column('comment'), |
|---|
| 46 | Column('attachment_path'), |
|---|
| 47 | Column('created', type='int'), |
|---|
| 48 | ], |
|---|
| 49 | ] |
|---|
| 50 | |
|---|
| 51 | def do_upgrade(env, ver, cursor): |
|---|
| 52 | """Add tables with new names.""" |
|---|
| 53 | |
|---|
| 54 | db_connector, _ = DatabaseManager(env).get_connector() |
|---|
| 55 | for tbl in tables: |
|---|
| 56 | for stmt in db_connector.to_sql(tbl): |
|---|
| 57 | cursor.execute(stmt) |
|---|
| 58 | |
|---|
| 59 | cursor.execute("""INSERT INTO peer_review(review_id,owner,status, created, name, notes) |
|---|
| 60 | SELECT IDReview, Author, Status, DateCreate, Name, Notes FROM CodeReviews""") |
|---|
| 61 | cursor.execute("""INSERT INTO peer_reviewer(review_id,reviewer,status, vote) |
|---|
| 62 | SELECT IDReview, Reviewer, Status, Vote FROM Reviewers""") |
|---|
| 63 | cursor.execute("""INSERT INTO peer_review_file(file_id,review_id,path,line_start,line_end, revision) |
|---|
| 64 | SELECT IDFile, IDReview, Path, LineStart, LineEnd, Version FROM ReviewFiles""") |
|---|
| 65 | cursor.execute("""INSERT INTO peer_review_comment(comment_id,file_id,parent_id,line_num,author,comment, |
|---|
| 66 | attachment_path, created) |
|---|
| 67 | SELECT IDComment, IDFile, IDParent, LineNum, Author, Text, AttachmentPath, DateCreate FROM ReviewComments""") |
|---|
| 68 | |
|---|
| 69 | cursor.execute("SELECT value FROM system WHERE name = %s", ('CodeReviewVoteThreshold',)) |
|---|
| 70 | row = cursor.fetchone() |
|---|
| 71 | env.config.set('peer-review', 'vote_threshold', row[0]) |
|---|
| 72 | env.config.save() |
|---|
| 73 | |
|---|
| 74 | cursor.execute("DELETE FROM system WHERE name = %s", ('CodeReviewVoteThreshold',)) |
|---|
| 75 | cursor.execute("DELETE FROM system WHERE name = %s", ('codereview_version',)) |
|---|
| 76 | cursor.execute("DROP TABLE CodeReviews") |
|---|
| 77 | cursor.execute("DROP TABLE Reviewers") |
|---|
| 78 | cursor.execute("DROP TABLE ReviewFiles") |
|---|
| 79 | cursor.execute("DROP TABLE ReviewComments") |
|---|