# HG changeset patch # User Julien Cristau # Date 1431971254 -7200 # Node ID f1773842077d0647c374c4671902200b0a7b53ba # Parent fb7c1013189eb390a6ccd38bd77f9bdf7308cb94 [hooks/syncschema] drop/add check constraints as appropriate Related to #5154406 diff -r fb7c1013189e -r f1773842077d hooks/syncschema.py --- a/hooks/syncschema.py Sun Mar 22 19:39:29 2015 +0100 +++ b/hooks/syncschema.py Mon May 18 19:47:34 2015 +0200 @@ -27,6 +27,7 @@ _ = unicode from copy import copy +from hashlib import md5 from yams.schema import (BASE_TYPES, BadSchemaDefinition, RelationSchema, RelationDefinitionSchema) from yams import buildobjs as ybo, convert_default_value @@ -705,6 +706,10 @@ elif cstrtype == 'UniqueConstraint': syssource.update_rdef_unique(cnx, rdef) self.unique_changed = True + if cstrtype in ('BoundaryConstraint', 'IntervalBoundConstraint', 'StaticVocabularyConstraint'): + cstrname = 'cstr' + md5(rdef.subject.type + rdef.rtype.type + cstrtype + + (self.oldcstr.serialize() or '')).hexdigest() + cnx.system_sql('ALTER TABLE %s%s DROP CONSTRAINT %s' % (SQL_PREFIX, rdef.subject.type, cstrname)) def revertprecommit_event(self): # revert changes on in memory schema @@ -752,6 +757,16 @@ elif cstrtype == 'UniqueConstraint' and oldcstr is None: syssource.update_rdef_unique(cnx, rdef) self.unique_changed = True + if cstrtype in ('BoundaryConstraint', 'IntervalBoundConstraint', 'StaticVocabularyConstraint'): + if oldcstr is not None: + oldcstrname = 'cstr' + md5(rdef.subject.type + rdef.rtype.type + cstrtype + + (self.oldcstr.serialize() or '')).hexdigest() + cnx.system_sql('ALTER TABLE %s%s DROP CONSTRAINT %s' % + (SQL_PREFIX, rdef.subject.type, oldcstrname)) + cstrname, check = y2sql.check_constraint(rdef.subject, rdef.object, rdef.rtype.type, + newcstr, syssource.dbhelper, prefix=SQL_PREFIX) + cnx.system_sql('ALTER TABLE %s%s ADD CONSTRAINT %s CHECK(%s)' % + (SQL_PREFIX, rdef.subject.type, cstrname, check)) class CWUniqueTogetherConstraintAddOp(MemSchemaOperation):