Ticket #986: trac-db-changes-r2881.patch
| File trac-db-changes-r2881.patch, 5.7 KB (added by Andres Salomon <dilinger@…>, 3 years ago) |
|---|
-
(a) /dev/null vs. (b) trac/upgrades/db17.py
=== added file 'trac/upgrades/db17.py'
a b 1 from trac.db import Table, Column, Index, DatabaseManager 2 3 def get_table_from_name(name): 4 from trac.core import TracError 5 from trac.db_default import schema 6 table = filter((lambda n: n.name == name), schema) 7 if len(table) != 1: 8 raise TracError, "Cannot find table '%s' in schema!" % name 9 return table[0] 10 11 def do_upgrade(env, ver, cursor): 12 # SQLite does not fully support ALTER, so we must use temp tables to 13 # rename node_change columns. 14 cursor.execute("CREATE TEMP TABLE nc_old AS SELECT * FROM node_change") 15 cursor.execute("DROP TABLE node_change") 16 db_backend, _ = DatabaseManager(env)._get_connector() 17 table = get_table_from_name('node_change') 18 for stmt in db_backend.to_sql(table): 19 cursor.execute(stmt) 20 cursor.execute("INSERT INTO node_change (rev,path,node_type,change_type," 21 "base_path,base_rev) SELECT rev,path,kind,change," 22 "base_path,base_rev FROM nc_old") -
trac/db_default.py
=== modified file 'trac/db_default.py'
18 18 from trac.db import Table, Column, Index 19 19 20 20 # Database version identifier. Used for automatic upgrades. 21 db_version = 1 621 db_version = 17 22 22 23 23 def __mkreports(reports): 24 24 """Utility function used to create report data in same syntax as the … … 83 83 Column('author'), 84 84 Column('message'), 85 85 Index(['time'])], 86 Table('node_change', key=('rev', 'path', 'change '))[86 Table('node_change', key=('rev', 'path', 'change_type'))[ 87 87 Column('rev'), 88 88 Column('path'), 89 Column(' kind', size=1),90 Column('change ', size=1),89 Column('node_type', size=1), 90 Column('change_type', size=1), 91 91 Column('base_path'), 92 92 Column('base_rev'), 93 93 Index(['rev'])], -
trac/versioncontrol/cache.py
=== modified file 'trac/versioncontrol/cache.py'
88 88 base_path, base_rev))) 89 89 kind = kindmap[kind] 90 90 action = actionmap[action] 91 cursor.execute("INSERT INTO node_change (rev,path, kind,"92 " change,base_path,base_rev) "91 cursor.execute("INSERT INTO node_change (rev,path," 92 "node_type,change_type,base_path,base_rev) " 93 93 "VALUES (%s,%s,%s,%s,%s,%s)", 94 94 (str(current_rev), path, kind, action, 95 95 base_path, base_rev)) … … 148 148 149 149 def get_changes(self): 150 150 cursor = self.db.cursor() 151 cursor.execute("SELECT path, kind,change,base_path,base_rev "151 cursor.execute("SELECT path,node_type,change_type,base_path,base_rev " 152 152 "FROM node_change WHERE rev=%s " 153 153 "ORDER BY path", (self.rev,)) 154 154 for path, kind, change, base_path, base_rev in cursor: -
trac/versioncontrol/tests/cache.py
=== modified file 'trac/versioncontrol/tests/cache.py'
68 68 self.assertEquals(('0', 41000, '', ''), cursor.fetchone()) 69 69 self.assertEquals(('1', 42000, 'joe', 'Import'), cursor.fetchone()) 70 70 self.assertEquals(None, cursor.fetchone()) 71 cursor.execute("SELECT rev,path, kind,change,base_path,base_rev"72 " FROM node_change")71 cursor.execute("SELECT rev,path,node_type,change_type,base_path," 72 "base_rev FROM node_change") 73 73 self.assertEquals(('1', 'trunk', 'D', 'A', None, None), 74 74 cursor.fetchone()) 75 75 self.assertEquals(('1', 'trunk/README', 'F', 'A', None, None), … … 82 82 "VALUES (0,41000,'','')") 83 83 cursor.execute("INSERT INTO revision (rev,time,author,message) " 84 84 "VALUES (1,42000,'joe','Import')") 85 cursor.executemany("INSERT INTO node_change (rev,path,kind,change," 86 "base_path,base_rev) VALUES ('1',%s,%s,%s,%s,%s)", 85 cursor.executemany("INSERT INTO node_change (rev,path,node_type," 86 "change_type,base_path,base_rev) " 87 "VALUES ('1',%s,%s,%s,%s,%s)", 87 88 [('trunk', 'D', 'A', None, None), 88 89 ('trunk/README', 'F', 'A', None, None)]) 89 90 … … 101 102 cursor.execute("SELECT time,author,message FROM revision WHERE rev='2'") 102 103 self.assertEquals((42042, 'joe', 'Update'), cursor.fetchone()) 103 104 self.assertEquals(None, cursor.fetchone()) 104 cursor.execute("SELECT path, kind,change,base_path,base_rev "105 cursor.execute("SELECT path,node_type,change_type,base_path,base_rev " 105 106 "FROM node_change WHERE rev='2'") 106 107 self.assertEquals(('trunk/README', 'F', 'E', 'trunk/README', '1'), 107 108 cursor.fetchone()) … … 113 114 "VALUES (0,41000,'','')") 114 115 cursor.execute("INSERT INTO revision (rev,time,author,message) " 115 116 "VALUES (1,42000,'joe','Import')") 116 cursor.executemany("INSERT INTO node_change (rev,path,kind,change," 117 "base_path,base_rev) VALUES ('1',%s,%s,%s,%s,%s)", 117 cursor.executemany("INSERT INTO node_change (rev,path,node_type," 118 "change_type,base_path,base_rev) " 119 "VALUES ('1',%s,%s,%s,%s,%s)", 118 120 [('trunk', 'D', 'A', None, None), 119 121 ('trunk/README', 'F', 'A', None, None)]) 120 122
