Commits

Anonymous committed 33bf728

First step towards MySQL support (#986): applied patch by Manuzhai and Adres Salomon that renames the columns in the `node_change` table to avoid a conflict with reserved words in MySQL.

Comments (0)

Files changed (5)

  * Mark Rowe                      mark.rowe@bdash.net.nz
  * Olliver Rutherfurd             ollie
  * pkou                           pkou@ua.fm
+ * Andres Salomon                 dilinger@athenacr.com
  * Michael Scherer                misc@mandrake.org
  * Andreas Schrattenecker         vittorio
  * Emmeran Seehuber               rototor@rototor.de
  * Jani Tiainen                   redetin@luukku.com
  * Zilvinas Valinskas             zilvinas@gemtek.lt
  * Jason Vasquez                  jason@mugfu.com
+ * Jeff Weiss                     trac@jeffweiss.org
  * Dmitry Yusupov                 dmitry_yus@yahoo.com
 
 The ever so elusive Anonymous.

trac/db_default.py

 from trac.db import Table, Column, Index
 
 # Database version identifier. Used for automatic upgrades.
-db_version = 16
+db_version = 17
 
 def __mkreports(reports):
     """Utility function used to create report data in same syntax as the
         Column('author'),
         Column('message'),
         Index(['time'])],
-    Table('node_change', key=('rev', 'path', 'change'))[
+    Table('node_change', key=('rev', 'path', 'change_type'))[
         Column('rev'),
         Column('path'),
-        Column('kind', size=1),
-        Column('change', size=1),
+        Column('node_type', size=1),
+        Column('change_type', size=1),
         Column('base_path'),
         Column('base_rev'),
         Index(['rev'])],

trac/upgrades/db17.py

+from trac.db import Table, Column, Index, DatabaseManager
+
+def do_upgrade(env, ver, cursor):
+    """Rename the columns `kind` and `change` in the `node_change` table for
+    compatibity with MySQL.
+    """
+    cursor.execute("CREATE TEMP TABLE nc_old AS SELECT * FROM node_change")
+    cursor.execute("DROP TABLE node_change")
+
+    table = Table('node_change', key=('rev', 'path', 'change_type'))[
+        Column('rev'),
+        Column('path'),
+        Column('node_type', size=1),
+        Column('change_type', size=1),
+        Column('base_path'),
+        Column('base_rev'),
+        Index(['rev'])
+    ]
+    db_connector, _ = DatabaseManager(env)._get_connector()
+    for stmt in db_connector.to_sql(table):
+        cursor.execute(stmt)
+
+    cursor.execute("INSERT INTO node_change (rev,path,node_type,change_type,"
+                   "base_path,base_rev) SELECT rev,path,kind,change,"
+                   "base_path,base_rev FROM nc_old")

trac/versioncontrol/cache.py

                                       base_path, base_rev)))
                     kind = kindmap[kind]
                     action = actionmap[action]
-                    cursor.execute("INSERT INTO node_change (rev,path,kind,"
-                                   "change,base_path,base_rev) "
+                    cursor.execute("INSERT INTO node_change (rev,path,"
+                                   "node_type,change_type,base_path,base_rev) "
                                    "VALUES (%s,%s,%s,%s,%s,%s)",
                                    (str(current_rev), path, kind, action,
                                    base_path, base_rev))
 
     def get_changes(self):
         cursor = self.db.cursor()
-        cursor.execute("SELECT path,kind,change,base_path,base_rev "
+        cursor.execute("SELECT path,node_type,change_type,base_path,base_rev "
                        "FROM node_change WHERE rev=%s "
                        "ORDER BY path", (self.rev,))
         for path, kind, change, base_path, base_rev in cursor:

trac/versioncontrol/tests/cache.py

         self.assertEquals(('0', 41000, '', ''), cursor.fetchone())
         self.assertEquals(('1', 42000, 'joe', 'Import'), cursor.fetchone())
         self.assertEquals(None, cursor.fetchone())
-        cursor.execute("SELECT rev,path,kind,change,base_path,base_rev "
-                       "FROM node_change")
+        cursor.execute("SELECT rev,path,node_type,change_type,base_path,"
+                       "base_rev FROM node_change")
         self.assertEquals(('1', 'trunk', 'D', 'A', None, None),
                           cursor.fetchone())
         self.assertEquals(('1', 'trunk/README', 'F', 'A', None, None),
                        "VALUES (0,41000,'','')")
         cursor.execute("INSERT INTO revision (rev,time,author,message) "
                        "VALUES (1,42000,'joe','Import')")
-        cursor.executemany("INSERT INTO node_change (rev,path,kind,change,"
-                           "base_path,base_rev) VALUES ('1',%s,%s,%s,%s,%s)",
+        cursor.executemany("INSERT INTO node_change (rev,path,node_type,"
+                           "change_type,base_path,base_rev) "
+                           "VALUES ('1',%s,%s,%s,%s,%s)",
                            [('trunk', 'D', 'A', None, None),
                             ('trunk/README', 'F', 'A', None, None)])
 
         cursor.execute("SELECT time,author,message FROM revision WHERE rev='2'")
         self.assertEquals((42042, 'joe', 'Update'), cursor.fetchone())
         self.assertEquals(None, cursor.fetchone())
-        cursor.execute("SELECT path,kind,change,base_path,base_rev "
+        cursor.execute("SELECT path,node_type,change_type,base_path,base_rev "
                        "FROM node_change WHERE rev='2'")
         self.assertEquals(('trunk/README', 'F', 'E', 'trunk/README', '1'),
                           cursor.fetchone())
                        "VALUES (0,41000,'','')")
         cursor.execute("INSERT INTO revision (rev,time,author,message) "
                        "VALUES (1,42000,'joe','Import')")
-        cursor.executemany("INSERT INTO node_change (rev,path,kind,change,"
-                           "base_path,base_rev) VALUES ('1',%s,%s,%s,%s,%s)",
+        cursor.executemany("INSERT INTO node_change (rev,path,node_type,"
+                           "change_type,base_path,base_rev) "
+                           "VALUES ('1',%s,%s,%s,%s,%s)",
                            [('trunk', 'D', 'A', None, None),
                             ('trunk/README', 'F', 'A', None, None)])