# HG changeset patch # User Sylvain Thénault # Date 1277103252 -7200 # Node ID 29c67578c9181701c9f370ec5b46cb02ebd4f17f # Parent 589e2e3fb9977606204b3c92008ca3c62fcf3974 [schema migration] fix backend compatibility issue by using type_from_constraints / sql_change_col_type instead of bare ALTER COLUMN diff -r 589e2e3fb997 -r 29c67578c918 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)