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

Last change on this file was 15192, checked in by Cinc-th, 8 years ago

Upgrade for database schema to version 2.

  • all table and column names are lower case now
  • table names are prepended by peer_ to prevent name clashes
  • added some columns for future features
  • uses Trac upgrade framework
  • table contents is properly migrated

Note that the upgrade is only tested with SQLite.

Refs #10812
Refs #5395
Fixes #5808
Fixes #5401



File size: 1.8 KB
Line 
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#
11from trac.db import Table, Column, DatabaseManager
12
13#The tables for the Code Review Plugin database version 1
14
15tables = [
16    Table('CodeReviews', key='IDReview')[
17        Column('IDReview', auto_increment=True, type='int'),
18        Column('Author'),
19        Column('Status'),
20        Column('DateCreate', type='int'),
21        Column('Name'),
22        Column('Notes'),
23    ],
24    Table('Reviewers', key=('IDReview', 'Reviewer'))[
25        Column('IDReview', type='int'),
26        Column('Reviewer'),
27        Column('Status', type='int'),
28        Column('Vote', type='int'),
29    ],
30    Table('ReviewFiles', key='IDFile')[
31        Column('IDFile', auto_increment=True, type='int'),
32        Column('IDReview', type='int'),
33        Column('Path'),
34        Column('LineStart', type='int'),
35        Column('LineEnd', type='int'),
36        Column('Version', type='int'),
37    ],
38    Table('ReviewComments', key='IDComment')[
39        Column('IDComment', auto_increment=True, type='int'),
40        Column('IDFile', type='int'),
41        Column('IDParent', type='int'),
42        Column('LineNum', type='int'),
43        Column('Author'),
44        Column('Text'),
45        Column('AttachmentPath'),
46        Column('DateCreate', type='int'),
47    ],
48]
49
50def do_upgrade(env, ver, cursor):
51    """Add tables."""
52    db_connector, _ = DatabaseManager(env).get_connector()
53    for tbl in tables:
54        for stmt in db_connector.to_sql(tbl):
55            cursor.execute(stmt)
56
57    cursor.execute("INSERT INTO system VALUES (%s, %s)", ('CodeReviewVoteThreshold', 0))
Note: See TracBrowser for help on using the repository browser.