Edgewall Software

Ticket #3676: remove_node_change_pk-r5133.diff

File remove_node_change_pk-r5133.diff, 2.9 KB (added by cboos, 20 months ago)

Simply remove the problematic index

  • trac/db_default.py

     
    1717from trac.db import Table, Column, Index 
    1818 
    1919# Database version identifier. Used for automatic upgrades. 
    20 db_version = 20 
     20db_version = 21 
    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')[ # MySQL can't have a key on path (see #3676) 
    9292        Column('rev'), 
    9393        Column('path'), 
    9494        Column('node_type', size=1), 
  • trac/db/mysql_backend.py

     
    8080            name = '`%s`' % c 
    8181            table_col = filter((lambda x: x.name == c), table.columns) 
    8282            if len(table_col) == 1 and table_col[0].type.lower() == 'text': 
    83                 if name == '`rev`': 
    84                     name += '(20)' 
    85                 elif name == '`path`': 
    86                     name += '(255)' 
    87                 elif name == '`change_type`': 
    88                     name += '(2)' 
    89                 else: 
    90                     name += '(%s)' % limit 
     83                name += '(%s)' % limit 
    9184            # For non-text columns, we simply throw away the extra bytes. 
    9285            # That could certainly be optimized better, but for now let's KISS. 
    9386            cols.append(name) 
  • trac/upgrades/db21.py

     
     1from trac.db import Table, Column, Index, DatabaseManager 
     2 
     3def do_upgrade(env, ver, cursor): 
     4    """Remove the primary key constraint on the `node_change` table, 
     5    as it's not used anyway and MySQL doesn't support it properly (#3676). 
     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 
     20    db_connector, _ = DatabaseManager(env)._get_connector() 
     21    for stmt in db_connector.to_sql(table): 
     22        cursor.execute(stmt) 
     23 
     24    cursor.execute("INSERT INTO node_change " 
     25                   "(rev,path,node_type,change_type,base_path,base_rev) " 
     26                   "SELECT rev,path,node_type,change_type,base_path,base_rev " 
     27                   "FROM node_change_old") 
     28    cursor.execute("DROP TABLE node_change_old")