# HG changeset patch # User Alexandre Fayolle # Date 1277395157 0 # Node ID d7256ae7c1d1a7c53127b10c8852c3aeb81bbee2 # Parent 16a4235e031f5337ad364aceb9bce9e78dc7e3e2 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) diff -r 16a4235e031f -r d7256ae7c1d1 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)