Commits

Anonymous committed 6423ae0

DB upgrade that adds the `authenticated` column to the compound key of the `session` table. Should fix #2051.

Comments (0)

Files changed (2)

trac/db_default.py

 from trac.db import Table, Column, Index
 
 # Database version identifier. Used for automatic upgrades.
-db_version = 14
+db_version = 15
 
 def __mkreports(reports):
     """Utility function used to create report data in same syntax as the
         Column('name'),
         Column('ipnr'),
         Column('time', type='int')],
-    Table('session', key=('sid', 'var_name'))[
+    Table('session', key=('sid', 'authenticated', 'var_name'))[
         Column('sid'),
         Column('authenticated', type='int'),
         Column('var_name'),
-        Column('var_value'),
-        Index(['sid', 'var_name'])],
+        Column('var_value')],
 
     # Attachments
     Table('attachment', key=('type', 'id', 'filename'))[
         Column('ipnr'),
         Column('text'),
         Column('comment'),
-        Column('readonly', type='int'),
-        Index(['name', 'version'])],
+        Column('readonly', type='int')],
 
     # Version control cache
     Table('revision', key='rev')[

trac/upgrades/db15.py

+from trac.db import Table, Column, Index
+
+def do_upgrade(env, ver, cursor):
+    cursor.execute("CREATE TEMP TABLE session_old AS SELECT * FROM session")
+    cursor.execute("DROP TABLE session")
+
+    db = env.get_db_cnx()
+    session_table = Table('session', key=('sid', 'authenticated', 'var_name'))[
+        Column('sid'),
+        Column('authenticated', type='int'),
+        Column('var_name'),
+        Column('var_value')]
+    for stmt in db.to_sql(session_table):
+        cursor.execute(stmt)
+
+    cursor.execute("INSERT INTO session (sid,authenticated,var_name,var_value) "
+                   "SELECT sid,authenticated,var_name,var_value "
+                   "FROM session_old")