[schema migration] fix backend compatibility issue by using type_from_constraints / sql_change_col_type instead of bare ALTER COLUMN stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 21 Jun 2010 08:54:12 +0200
branchstable
changeset 5804 29c67578c918
parent 5803 589e2e3fb997
child 5805 560cde8a4f9f
[schema migration] fix backend compatibility issue by using type_from_constraints / sql_change_col_type instead of bare ALTER COLUMN
hooks/syncschema.py
--- a/hooks/syncschema.py	Mon Jun 21 08:53:13 2010 +0200
+++ b/hooks/syncschema.py	Mon Jun 21 08:54:12 2010 +0200
@@ -552,8 +552,8 @@
             sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
             try:
                 session.system_sql(sql, rollback_on_failure=False)
-                self.info('altered column %s of table %s: now VARCHAR(%s)',
-                          column, table, newcstr.max)
+                self.info('altered column %s of table %s: now %s',
+                          column, table, coltype)
             except Exception, ex:
                 # not supported by sqlite for instance
                 self.error('error while altering table %s: %s', table, ex)
@@ -568,16 +568,19 @@
 
     def precommit_event(self):
         cstrtype = self.cstr.type()
-        table = SQL_PREFIX + str(self.subjtype)
-        column = SQL_PREFIX + str(self.rtype)
+        table = SQL_PREFIX + str(self.rdef.subject)
+        column = SQL_PREFIX + str(self.rdef.rtype)
         # alter the physical schema on size/unique constraint changes
         if cstrtype == 'SizeConstraint':
             try:
-                self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT'
-                                        % (table, column),
-                                        rollback_on_failure=False)
-                self.info('altered column %s of table %s: now TEXT',
-                          column, table)
+                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')
+                self.session.system_sql(sql, rollback_on_failure=False)
+                self.info('altered column %s of table %s: now %s',
+                          column, table, coltype)
             except Exception, ex:
                 # not supported by sqlite for instance
                 self.error('error while altering table %s: %s', table, ex)
@@ -1109,8 +1112,7 @@
         except IndexError:
             self._cw.critical('constraint type no more accessible')
         else:
-            SourceDbCWConstraintDel(self._cw, cstr=cstr,
-                                    subjtype=rdef.subject, rtype=rdef.rtype)
+            SourceDbCWConstraintDel(self._cw, rdef=rdef, cstr=cstr)
             MemSchemaCWConstraintDel(self._cw, rdef=rdef, cstr=cstr)