Edgewall Software

Ticket #3778: node_change_upgrade-r3787.patch

File node_change_upgrade-r3787.patch, 2.4 KB (added by cboos, 2 years ago)

Replace the primary key constraint by a (non-unique) index on the node_change table

  • trac/db_default.py

     
    1717from trac.db import Table, Column, Index 
    1818 
    1919# Database version identifier. Used for automatic upgrades. 
    20 db_version = 19 
     20db_version = 20 
    2121 
    2222def __mkreports(reports): 
    2323    """Utility function used to create report data in same syntax as the 
     
    8888        Column('author'), 
    8989        Column('message'), 
    9090        Index(['time'])], 
    91     Table('node_change', key=('rev', 'path', 'change_type'))[ 
     91    Table('node_change')[ 
    9292        Column('rev'), 
    9393        Column('path'), 
    9494        Column('node_type', size=1), 
    9595        Column('change_type', size=1), 
    9696        Column('base_path'), 
    9797        Column('base_rev'), 
    98         Index(['rev'])], 
     98        Index(['rev']), 
     99        Index(['rev', 'path', 'change_type'])], 
    99100 
    100101    # Ticket system 
    101102    Table('ticket', key='id')[ 
  • trac/upgrades/db20.py

     
     1from trac.db import Table, Column, Index, DatabaseManager 
     2 
     3def do_upgrade(env, ver, cursor): 
     4    """Replace the primary key constraint on the `node_change` table by an 
     5    index, as the key is not unique in some circumstances (#3778). 
     6    """ 
     7    cursor.execute("CREATE TEMPORARY TABLE node_change_old AS " 
     8                   "SELECT * FROM node_change") 
     9    cursor.execute("DROP TABLE node_change") 
     10 
     11    table = Table('node_change')[ 
     12        Column('rev'), 
     13        Column('path'), 
     14        Column('node_type', size=1), 
     15        Column('change_type', size=1), 
     16        Column('base_path'), 
     17        Column('base_rev'), 
     18        Index(['rev']), 
     19        Index(['rev', 'path', 'change_type'])] 
     20 
     21    db_connector, _ = DatabaseManager(env)._get_connector() 
     22    for stmt in db_connector.to_sql(table): 
     23        cursor.execute(stmt) 
     24 
     25    cursor.execute("INSERT INTO node_change " 
     26                   "(rev,path,node_type,change_type,base_path,base_rev) " 
     27                   "SELECT rev,path,node_type,change_type,base_path,base_rev " 
     28                   "FROM node_change_old") 
     29    cursor.execute("DROP TABLE node_change_old")