699 # then update database: alter the physical schema on size/unique |
699 # then update database: alter the physical schema on size/unique |
700 # constraint changes |
700 # constraint changes |
701 syssource = cnx.repo.system_source |
701 syssource = cnx.repo.system_source |
702 cstrtype = self.oldcstr.type() |
702 cstrtype = self.oldcstr.type() |
703 if cstrtype == 'SizeConstraint': |
703 if cstrtype == 'SizeConstraint': |
|
704 # if the size constraint is being replaced with a new max size, we'll |
|
705 # call update_rdef_column in CWConstraintAddOp, skip it here |
|
706 for cstr in cnx.transaction_data.get('newsizecstr', ()): |
|
707 rdefentity = cstr.reverse_constrained_by[0] |
|
708 cstrrdef = cnx.vreg.schema.schema_by_eid(rdefentity.eid) |
|
709 if cstrrdef == rdef: |
|
710 return |
|
711 |
|
712 # we found that the size constraint for this rdef is really gone, |
|
713 # not just replaced by another |
704 syssource.update_rdef_column(cnx, rdef) |
714 syssource.update_rdef_column(cnx, rdef) |
705 self.size_cstr_changed = True |
715 self.size_cstr_changed = True |
706 elif cstrtype == 'UniqueConstraint': |
716 elif cstrtype == 'UniqueConstraint': |
707 syssource.update_rdef_unique(cnx, rdef) |
717 syssource.update_rdef_unique(cnx, rdef) |
708 self.unique_changed = True |
718 self.unique_changed = True |
792 |
802 |
793 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation): |
803 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation): |
794 entity = cstrname = None # for pylint |
804 entity = cstrname = None # for pylint |
795 cols = () # for pylint |
805 cols = () # for pylint |
796 |
806 |
|
807 def insert_index(self): |
|
808 # We need to run before CWConstraintDelOp: if a size constraint is |
|
809 # removed and the column is part of a unique_together constraint, we |
|
810 # remove the unique_together index before changing the column's type. |
|
811 # SQL Server does not support unique indices on unlimited text columns. |
|
812 return 0 |
|
813 |
797 def precommit_event(self): |
814 def precommit_event(self): |
798 cnx = self.cnx |
815 cnx = self.cnx |
799 prefix = SQL_PREFIX |
816 prefix = SQL_PREFIX |
800 table = '%s%s' % (prefix, self.entity.type) |
817 table = '%s%s' % (prefix, self.entity.type) |
801 dbhelper = cnx.repo.system_source.dbhelper |
818 dbhelper = cnx.repo.system_source.dbhelper |
1222 __regid__ = 'syncaddcwconstraint' |
1239 __regid__ = 'syncaddcwconstraint' |
1223 __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint') |
1240 __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint') |
1224 events = ('after_add_entity', 'after_update_entity') |
1241 events = ('after_add_entity', 'after_update_entity') |
1225 |
1242 |
1226 def __call__(self): |
1243 def __call__(self): |
|
1244 if self.entity.cstrtype[0].name == 'SizeConstraint': |
|
1245 txdata = self._cw.transaction_data |
|
1246 if 'newsizecstr' not in txdata: |
|
1247 txdata['newsizecstr'] = set() |
|
1248 txdata['newsizecstr'].add(self.entity) |
1227 CWConstraintAddOp(self._cw, entity=self.entity) |
1249 CWConstraintAddOp(self._cw, entity=self.entity) |
1228 |
1250 |
1229 |
1251 |
1230 class AfterAddConstrainedByHook(SyncSchemaHook): |
1252 class AfterAddConstrainedByHook(SyncSchemaHook): |
1231 __regid__ = 'syncaddconstrainedby' |
1253 __regid__ = 'syncaddconstrainedby' |