Edgewall Software

Ticket #986: trac-db-changes-r2881.patch

File trac-db-changes-r2881.patch, 5.7 KB (added by Andres Salomon <dilinger@…>, 3 years ago)

updated db-changes patch against 2881

  • (a) /dev/null vs. (b) trac/upgrades/db17.py

    === added file 'trac/upgrades/db17.py'
    a b  
     1from trac.db import Table, Column, Index, DatabaseManager 
     2 
     3def 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 
     11def 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'
     
    1818from trac.db import Table, Column, Index 
    1919 
    2020# Database version identifier. Used for automatic upgrades. 
    21 db_version = 16 
     21db_version = 17 
    2222 
    2323def __mkreports(reports): 
    2424    """Utility function used to create report data in same syntax as the 
     
    8383        Column('author'), 
    8484        Column('message'), 
    8585        Index(['time'])], 
    86     Table('node_change', key=('rev', 'path', 'change'))[ 
     86    Table('node_change', key=('rev', 'path', 'change_type'))[ 
    8787        Column('rev'), 
    8888        Column('path'), 
    89         Column('kind', size=1), 
    90         Column('change', size=1), 
     89        Column('node_type', size=1), 
     90        Column('change_type', size=1), 
    9191        Column('base_path'), 
    9292        Column('base_rev'), 
    9393        Index(['rev'])], 
  • trac/versioncontrol/cache.py

    === modified file 'trac/versioncontrol/cache.py'
     
    8888                                      base_path, base_rev))) 
    8989                    kind = kindmap[kind] 
    9090                    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) " 
    9393                                   "VALUES (%s,%s,%s,%s,%s,%s)", 
    9494                                   (str(current_rev), path, kind, action, 
    9595                                   base_path, base_rev)) 
     
    148148 
    149149    def get_changes(self): 
    150150        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 " 
    152152                       "FROM node_change WHERE rev=%s " 
    153153                       "ORDER BY path", (self.rev,)) 
    154154        for path, kind, change, base_path, base_rev in cursor: 
  • trac/versioncontrol/tests/cache.py

    === modified file 'trac/versioncontrol/tests/cache.py'
     
    6868        self.assertEquals(('0', 41000, '', ''), cursor.fetchone()) 
    6969        self.assertEquals(('1', 42000, 'joe', 'Import'), cursor.fetchone()) 
    7070        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") 
    7373        self.assertEquals(('1', 'trunk', 'D', 'A', None, None), 
    7474                          cursor.fetchone()) 
    7575        self.assertEquals(('1', 'trunk/README', 'F', 'A', None, None), 
     
    8282                       "VALUES (0,41000,'','')") 
    8383        cursor.execute("INSERT INTO revision (rev,time,author,message) " 
    8484                       "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)", 
    8788                           [('trunk', 'D', 'A', None, None), 
    8889                            ('trunk/README', 'F', 'A', None, None)]) 
    8990 
     
    101102        cursor.execute("SELECT time,author,message FROM revision WHERE rev='2'") 
    102103        self.assertEquals((42042, 'joe', 'Update'), cursor.fetchone()) 
    103104        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 " 
    105106                       "FROM node_change WHERE rev='2'") 
    106107        self.assertEquals(('trunk/README', 'F', 'E', 'trunk/README', '1'), 
    107108                          cursor.fetchone()) 
     
    113114                       "VALUES (0,41000,'','')") 
    114115        cursor.execute("INSERT INTO revision (rev,time,author,message) " 
    115116                       "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)", 
    118120                           [('trunk', 'D', 'A', None, None), 
    119121                            ('trunk/README', 'F', 'A', None, None)]) 
    120122