fix schema migration hooks (partial) stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Thu, 24 Jun 2010 15:59:17 +0000
branchstable
changeset 5833 d7256ae7c1d1
parent 5832 16a4235e031f
child 5834 b8ad49864928
fix schema migration hooks (partial) SQL Server requires some additional steps to alter columns (index drop and restore, etc...) and this in turn requires passing a connection on the DB to find out the indexes. Also partially fix an issue where the null_allowed value was not correctly computed. Still some problems in there (see https://www.logilab.net/cwo/ticket/1109558)
hooks/syncschema.py
--- a/hooks/syncschema.py	Thu Jun 24 12:36:22 2010 +0200
+++ b/hooks/syncschema.py	Thu Jun 24 15:59:17 2010 +0000
@@ -516,7 +516,11 @@
                                                   creating=False)
             # XXX check self.values['cardinality'][0] actually changed?
             notnull = self.values['cardinality'][0] != '1'
-            sql = adbh.sql_set_null_allowed(table, column, coltype, notnull)
+            if getattr(adbh, 'alter_table_requires_cursor', False):
+                sql = adbh.sql_set_null_allowed(table, column, coltype, notnull, 
+                                                self.session.system_sql)
+            else:
+                sql = adbh.sql_set_null_allowed(table, column, coltype, notnull)
             session.system_sql(sql)
         if 'fulltextindexed' in self.values:
             UpdateFTIndexOp(session)
@@ -551,7 +555,11 @@
             card = rtype.rdef(subjtype, objtype).cardinality
             coltype = y2sql.type_from_constraints(adbh, objtype, [newcstr],
                                                   creating=False)
-            sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
+            if getattr(adbh, 'alter_table_requires_cursor', False):
+                sql = adbh.sql_change_col_type(table, column, coltype, card[0] != '1',
+                                               self.session.system_sql)
+            else:
+                sql = adbh.sql_change_col_type(table, column, coltype, card[0] != '1')
             try:
                 session.system_sql(sql, rollback_on_failure=False)
                 self.info('altered column %s of table %s: now %s',
@@ -578,8 +586,15 @@
                 adbh = self.session.pool.source('system').dbhelper
                 coltype = y2sql.type_from_constraints(adbh, rdef.object, [],
                                                       creating=False)
-                sql = adbh.sql_change_col_type(table, column, coltype,
-                                               rdef.cardinality != '1')
+    
+                if getattr(adbh, 'alter_table_requires_cursor', False):
+                    sql = adbh.sql_change_col_type(table, column, coltype,
+                                                   rdef.cardinality[0] != '1',
+                                                   self.session.system_sql)
+                else:
+                    sql = adbh.sql_change_col_type(table, column, coltype,
+                                               rdef.cardinality[0] != '1')
+                
                 self.session.system_sql(sql, rollback_on_failure=False)
                 self.info('altered column %s of table %s: now %s',
                           column, table, coltype)