hooks/syncschema.py
branchstable
changeset 5804 29c67578c918
parent 5803 589e2e3fb997
child 5805 560cde8a4f9f
equal deleted inserted replaced
5803:589e2e3fb997 5804:29c67578c918
   550             coltype = y2sql.type_from_constraints(adbh, objtype, [newcstr],
   550             coltype = y2sql.type_from_constraints(adbh, objtype, [newcstr],
   551                                                   creating=False)
   551                                                   creating=False)
   552             sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
   552             sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
   553             try:
   553             try:
   554                 session.system_sql(sql, rollback_on_failure=False)
   554                 session.system_sql(sql, rollback_on_failure=False)
   555                 self.info('altered column %s of table %s: now VARCHAR(%s)',
   555                 self.info('altered column %s of table %s: now %s',
   556                           column, table, newcstr.max)
   556                           column, table, coltype)
   557             except Exception, ex:
   557             except Exception, ex:
   558                 # not supported by sqlite for instance
   558                 # not supported by sqlite for instance
   559                 self.error('error while altering table %s: %s', table, ex)
   559                 self.error('error while altering table %s: %s', table, ex)
   560         elif cstrtype == 'UniqueConstraint' and oldcstr is None:
   560         elif cstrtype == 'UniqueConstraint' and oldcstr is None:
   561             session.pool.source('system').create_index(
   561             session.pool.source('system').create_index(
   566     """actually remove a constraint of a relation definition"""
   566     """actually remove a constraint of a relation definition"""
   567     rtype = subjtype = None # make pylint happy
   567     rtype = subjtype = None # make pylint happy
   568 
   568 
   569     def precommit_event(self):
   569     def precommit_event(self):
   570         cstrtype = self.cstr.type()
   570         cstrtype = self.cstr.type()
   571         table = SQL_PREFIX + str(self.subjtype)
   571         table = SQL_PREFIX + str(self.rdef.subject)
   572         column = SQL_PREFIX + str(self.rtype)
   572         column = SQL_PREFIX + str(self.rdef.rtype)
   573         # alter the physical schema on size/unique constraint changes
   573         # alter the physical schema on size/unique constraint changes
   574         if cstrtype == 'SizeConstraint':
   574         if cstrtype == 'SizeConstraint':
   575             try:
   575             try:
   576                 self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT'
   576                 adbh = self.session.pool.source('system').dbhelper
   577                                         % (table, column),
   577                 coltype = y2sql.type_from_constraints(adbh, rdef.object, [],
   578                                         rollback_on_failure=False)
   578                                                       creating=False)
   579                 self.info('altered column %s of table %s: now TEXT',
   579                 sql = adbh.sql_change_col_type(table, column, coltype,
   580                           column, table)
   580                                                rdef.cardinality != '1')
       
   581                 self.session.system_sql(sql, rollback_on_failure=False)
       
   582                 self.info('altered column %s of table %s: now %s',
       
   583                           column, table, coltype)
   581             except Exception, ex:
   584             except Exception, ex:
   582                 # not supported by sqlite for instance
   585                 # not supported by sqlite for instance
   583                 self.error('error while altering table %s: %s', table, ex)
   586                 self.error('error while altering table %s: %s', table, ex)
   584         elif cstrtype == 'UniqueConstraint':
   587         elif cstrtype == 'UniqueConstraint':
   585             self.session.pool.source('system').drop_index(
   588             self.session.pool.source('system').drop_index(
  1107         try:
  1110         try:
  1108             cstr = rdef.constraint_by_type(entity.type)
  1111             cstr = rdef.constraint_by_type(entity.type)
  1109         except IndexError:
  1112         except IndexError:
  1110             self._cw.critical('constraint type no more accessible')
  1113             self._cw.critical('constraint type no more accessible')
  1111         else:
  1114         else:
  1112             SourceDbCWConstraintDel(self._cw, cstr=cstr,
  1115             SourceDbCWConstraintDel(self._cw, rdef=rdef, cstr=cstr)
  1113                                     subjtype=rdef.subject, rtype=rdef.rtype)
       
  1114             MemSchemaCWConstraintDel(self._cw, rdef=rdef, cstr=cstr)
  1116             MemSchemaCWConstraintDel(self._cw, rdef=rdef, cstr=cstr)
  1115 
  1117 
  1116 
  1118 
  1117 # permissions synchronization hooks ############################################
  1119 # permissions synchronization hooks ############################################
  1118 
  1120