| 1 | #!/usr/bin/env python
|
|---|
| 2 | #
|
|---|
| 3 | # svntrac
|
|---|
| 4 | #
|
|---|
| 5 | # Copyright (C) 2002, 2003 Jonas Borgström <jonas@codefactory.se>
|
|---|
| 6 | #
|
|---|
| 7 | # svntrac is free software; you can redistribute it and/or
|
|---|
| 8 | # modify it under the terms of the GNU General Public License as
|
|---|
| 9 | # published by the Free Software Foundation; either version 2 of the
|
|---|
| 10 | # License, or (at your option) any later version.
|
|---|
| 11 | #
|
|---|
| 12 | # svntrac is distributed in the hope that it will be useful,
|
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 15 | # General Public License for more details.
|
|---|
| 16 | #
|
|---|
| 17 | # You should have received a copy of the GNU General Public License
|
|---|
| 18 | # along with this program; if not, write to the Free Software
|
|---|
| 19 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 20 | #
|
|---|
| 21 | # Author: Jonas Borgström <jonas@codefactory.se>
|
|---|
| 22 |
|
|---|
| 23 | import sys
|
|---|
| 24 | import sqlite
|
|---|
| 25 |
|
|---|
| 26 | def usage():
|
|---|
| 27 | print
|
|---|
| 28 | print 'Initializes/creates a new (empty) svntrac database'
|
|---|
| 29 | print
|
|---|
| 30 | print 'usage: %s <dbfilename>' % sys.argv[0]
|
|---|
| 31 | print
|
|---|
| 32 | sys.exit(1)
|
|---|
| 33 |
|
|---|
| 34 | def create_tables (cursor):
|
|---|
| 35 | cursor.execute ("""
|
|---|
| 36 | CREATE TABLE revision (
|
|---|
| 37 | rev integer PRIMARY KEY,
|
|---|
| 38 | time integer,
|
|---|
| 39 | author text,
|
|---|
| 40 | message text
|
|---|
| 41 | );
|
|---|
| 42 | CREATE TABLE node_change (
|
|---|
| 43 | rev integer,
|
|---|
| 44 | name text,
|
|---|
| 45 | change char(1),
|
|---|
| 46 | UNIQUE(rev, name, change)
|
|---|
| 47 | );
|
|---|
| 48 | CREATE TABLE auth_cookie (
|
|---|
| 49 | cookie text,
|
|---|
| 50 | name text,
|
|---|
| 51 | ipnr text,
|
|---|
| 52 | time integer,
|
|---|
| 53 | UNIQUE(cookie, name, ipnr)
|
|---|
| 54 | );
|
|---|
| 55 | CREATE TABLE enum (
|
|---|
| 56 | type text,
|
|---|
| 57 | name text,
|
|---|
| 58 | value text,
|
|---|
| 59 | UNIQUE(name,type)
|
|---|
| 60 | );
|
|---|
| 61 | CREATE TABLE ticket (
|
|---|
| 62 | id integer PRIMARY KEY,
|
|---|
| 63 | time integer, -- the time it was created
|
|---|
| 64 | changetime integer,
|
|---|
| 65 | component text,
|
|---|
| 66 | severity text,
|
|---|
| 67 | priority text,
|
|---|
| 68 | owner text, -- who is this ticket assigned to
|
|---|
| 69 | reporter text,
|
|---|
| 70 | cc text, -- email addresses to notify
|
|---|
| 71 | url text, -- url related to this ticket
|
|---|
| 72 | version text, --
|
|---|
| 73 | milestone text, --
|
|---|
| 74 | status text,
|
|---|
| 75 | resolution text,
|
|---|
| 76 | summary text, -- one-line summary
|
|---|
| 77 | description text -- problem description (long)
|
|---|
| 78 | );
|
|---|
| 79 | CREATE TABLE ticket_change (
|
|---|
| 80 | ticket integer,
|
|---|
| 81 | time integer,
|
|---|
| 82 | author text,
|
|---|
| 83 | field text,
|
|---|
| 84 | oldvalue text,
|
|---|
| 85 | newvalue text
|
|---|
| 86 | );
|
|---|
| 87 | CREATE TABLE report (
|
|---|
| 88 | id integer PRIMARY KEY,
|
|---|
| 89 | author text,
|
|---|
| 90 | title text,
|
|---|
| 91 | sql text
|
|---|
| 92 | );
|
|---|
| 93 | CREATE TABLE permission (
|
|---|
| 94 | user text, --
|
|---|
| 95 | action text -- allowable activity
|
|---|
| 96 | );
|
|---|
| 97 | CREATE TABLE component (
|
|---|
| 98 | name text PRIMARY KEY,
|
|---|
| 99 | owner text
|
|---|
| 100 | );
|
|---|
| 101 | CREATE TABLE milestone (
|
|---|
| 102 | name text PRIMARY KEY,
|
|---|
| 103 | time integer
|
|---|
| 104 | );
|
|---|
| 105 | CREATE TABLE version (
|
|---|
| 106 | name text PRIMARY KEY,
|
|---|
| 107 | time integer
|
|---|
| 108 | );
|
|---|
| 109 | CREATE TABLE wiki (
|
|---|
| 110 | name text,
|
|---|
| 111 | version integer,
|
|---|
| 112 | time integer,
|
|---|
| 113 | author text,
|
|---|
| 114 | ipnr text,
|
|---|
| 115 | locked integer,
|
|---|
| 116 | text text,
|
|---|
| 117 | UNIQUE(name,version)
|
|---|
| 118 | );
|
|---|
| 119 | """)
|
|---|
| 120 |
|
|---|
| 121 | def insert_default_values (cursor):
|
|---|
| 122 | cursor.execute ("""
|
|---|
| 123 | CREATE INDEX node_change_idx ON node_change(rev);
|
|---|
| 124 | CREATE INDEX ticket_change_idx ON ticket_change(ticket, time);
|
|---|
| 125 | CREATE INDEX wiki_idx ON wiki(name,version);
|
|---|
| 126 |
|
|---|
| 127 | INSERT INTO component (name, owner) VALUES('general', 'jonas');
|
|---|
| 128 | INSERT INTO component (name, owner) VALUES('report system', 'jonas');
|
|---|
| 129 | INSERT INTO component (name, owner) VALUES('browser', 'jonas');
|
|---|
| 130 | INSERT INTO component (name, owner) VALUES('timeline', 'jonas');
|
|---|
| 131 | INSERT INTO component (name, owner) VALUES('ticket system', 'jonas');
|
|---|
| 132 |
|
|---|
| 133 | INSERT INTO milestone (name, time) VALUES('', 0);
|
|---|
| 134 | INSERT INTO milestone (name, time) VALUES('milestone1', 0);
|
|---|
| 135 | INSERT INTO milestone (name, time) VALUES('milestone2', 0);
|
|---|
| 136 | INSERT INTO milestone (name, time) VALUES('milestone3', 0);
|
|---|
| 137 | INSERT INTO milestone (name, time) VALUES('milestone4', 0);
|
|---|
| 138 |
|
|---|
| 139 | INSERT INTO version (name, time) VALUES('', 0);
|
|---|
| 140 | INSERT INTO version (name, time) VALUES('1.0', 0);
|
|---|
| 141 | INSERT INTO version (name, time) VALUES('2.0', 0);
|
|---|
| 142 |
|
|---|
| 143 | INSERT INTO enum (type, name, value) VALUES('status', 'new', 1);
|
|---|
| 144 | INSERT INTO enum (type, name, value) VALUES('status', 'assigned', 2);
|
|---|
| 145 | INSERT INTO enum (type, name, value) VALUES('status', 'reopened', 3);
|
|---|
| 146 | INSERT INTO enum (type, name, value) VALUES('status', 'closed', 4);
|
|---|
| 147 |
|
|---|
| 148 | INSERT INTO enum (type, name, value) VALUES('resolution', 'fixed', 1);
|
|---|
| 149 | INSERT INTO enum (type, name, value) VALUES('resolution', 'invalid', 2);
|
|---|
| 150 | INSERT INTO enum (type, name, value) VALUES('resolution', 'wontfix', 3);
|
|---|
| 151 | INSERT INTO enum (type, name, value) VALUES('resolution', 'duplicate', 4);
|
|---|
| 152 | INSERT INTO enum (type, name, value) VALUES('resolution', 'worksforme', 5);
|
|---|
| 153 |
|
|---|
| 154 | INSERT INTO enum (type, name, value) VALUES('severity', 'blocker', 1);
|
|---|
| 155 | INSERT INTO enum (type, name, value) VALUES('severity', 'critical', 2);
|
|---|
| 156 | INSERT INTO enum (type, name, value) VALUES('severity', 'major', 3);
|
|---|
| 157 | INSERT INTO enum (type, name, value) VALUES('severity', 'normal', 4);
|
|---|
| 158 | INSERT INTO enum (type, name, value) VALUES('severity', 'minor', 5);
|
|---|
| 159 | INSERT INTO enum (type, name, value) VALUES('severity', 'trivial', 6);
|
|---|
| 160 | INSERT INTO enum (type, name, value) VALUES('severity', 'enhancement', 7);
|
|---|
| 161 |
|
|---|
| 162 | INSERT INTO enum (type, name, value) VALUES('priority', 'p1', 1);
|
|---|
| 163 | INSERT INTO enum (type, name, value) VALUES('priority', 'p2', 2);
|
|---|
| 164 | INSERT INTO enum (type, name, value) VALUES('priority', 'p3', 3);
|
|---|
| 165 | INSERT INTO enum (type, name, value) VALUES('priority', 'p4', 4);
|
|---|
| 166 | INSERT INTO enum (type, name, value) VALUES('priority', 'p5', 5);
|
|---|
| 167 |
|
|---|
| 168 | INSERT INTO permission (user, action) VALUES('anonymous', 'LOG_VIEW');
|
|---|
| 169 | INSERT INTO permission (user, action) VALUES('anonymous', 'FILE_VIEW');
|
|---|
| 170 | INSERT INTO permission (user, action) VALUES('anonymous', 'REPORT_VIEW');
|
|---|
| 171 | INSERT INTO permission (user, action) VALUES('anonymous', 'TICKET_VIEW');
|
|---|
| 172 | INSERT INTO permission (user, action) VALUES('anonymous', 'BROWSER_VIEW');
|
|---|
| 173 | INSERT INTO permission (user, action) VALUES('anonymous', 'TIMELINE_VIEW');
|
|---|
| 174 | INSERT INTO permission (user, action) VALUES('anonymous', 'CHANGESET_VIEW');
|
|---|
| 175 |
|
|---|
| 176 | INSERT INTO report (id, author, title, sql)
|
|---|
| 177 | VALUES (1, NULL, 'active tickets',
|
|---|
| 178 | "SELECT id AS ticket, status,
|
|---|
| 179 | severity, priority, owner, time as created, summary
|
|---|
| 180 | FROM ticket
|
|---|
| 181 | WHERE status IN ('new', 'assigned', 'reopened')
|
|---|
| 182 | ORDER BY priority, time"
|
|---|
| 183 | );
|
|---|
| 184 | """)
|
|---|
| 185 |
|
|---|
| 186 | def initialize_db (name):
|
|---|
| 187 | print 'Initializing "%s"...' % name,
|
|---|
| 188 | try:
|
|---|
| 189 | cnx = sqlite.connect (name)
|
|---|
| 190 | except Exception, e:
|
|---|
| 191 | print 'Failed to open/create database.'
|
|---|
| 192 | sys.exit(1)
|
|---|
| 193 | try:
|
|---|
| 194 | cursor = cnx.cursor ()
|
|---|
| 195 | create_tables (cursor)
|
|---|
| 196 | insert_default_values (cursor)
|
|---|
| 197 | cnx.commit()
|
|---|
| 198 | except Exception, e:
|
|---|
| 199 | print 'Failed to initialize database.'
|
|---|
| 200 | cnx.rollback()
|
|---|
| 201 | sys.exit(1)
|
|---|
| 202 | print 'done\n'
|
|---|
| 203 |
|
|---|
| 204 | def main():
|
|---|
| 205 | if len(sys.argv) != 2:
|
|---|
| 206 | usage()
|
|---|
| 207 |
|
|---|
| 208 | initialize_db (sys.argv[1])
|
|---|
| 209 |
|
|---|
| 210 | if __name__ == '__main__':
|
|---|
| 211 | main()
|
|---|
| 212 |
|
|---|