694 # then update database: alter the physical schema on size/unique |
694 # then update database: alter the physical schema on size/unique |
695 # constraint changes |
695 # constraint changes |
696 syssource = cnx.repo.system_source |
696 syssource = cnx.repo.system_source |
697 cstrtype = self.oldcstr.type() |
697 cstrtype = self.oldcstr.type() |
698 if cstrtype == 'SizeConstraint': |
698 if cstrtype == 'SizeConstraint': |
|
699 # if the size constraint is being replaced with a new max size, we'll |
|
700 # call update_rdef_column in CWConstraintAddOp, skip it here |
|
701 for cstr in cnx.transaction_data.get('newsizecstr', ()): |
|
702 rdefentity = cstr.reverse_constrained_by[0] |
|
703 cstrrdef = cnx.vreg.schema.schema_by_eid(rdefentity.eid) |
|
704 if cstrrdef == rdef: |
|
705 return |
|
706 |
|
707 # we found that the size constraint for this rdef is really gone, |
|
708 # not just replaced by another |
699 syssource.update_rdef_column(cnx, rdef) |
709 syssource.update_rdef_column(cnx, rdef) |
700 self.size_cstr_changed = True |
710 self.size_cstr_changed = True |
701 elif cstrtype == 'UniqueConstraint': |
711 elif cstrtype == 'UniqueConstraint': |
702 syssource.update_rdef_unique(cnx, rdef) |
712 syssource.update_rdef_unique(cnx, rdef) |
703 self.unique_changed = True |
713 self.unique_changed = True |
773 |
783 |
774 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation): |
784 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation): |
775 entity = cstrname = None # for pylint |
785 entity = cstrname = None # for pylint |
776 cols = () # for pylint |
786 cols = () # for pylint |
777 |
787 |
|
788 def insert_index(self): |
|
789 # We need to run before CWConstraintDelOp: if a size constraint is |
|
790 # removed and the column is part of a unique_together constraint, we |
|
791 # remove the unique_together index before changing the column's type. |
|
792 # SQL Server does not support unique indices on unlimited text columns. |
|
793 return 0 |
|
794 |
778 def precommit_event(self): |
795 def precommit_event(self): |
779 cnx = self.cnx |
796 cnx = self.cnx |
780 prefix = SQL_PREFIX |
797 prefix = SQL_PREFIX |
781 table = '%s%s' % (prefix, self.entity.type) |
798 table = '%s%s' % (prefix, self.entity.type) |
782 dbhelper = cnx.repo.system_source.dbhelper |
799 dbhelper = cnx.repo.system_source.dbhelper |
1203 __regid__ = 'syncaddcwconstraint' |
1220 __regid__ = 'syncaddcwconstraint' |
1204 __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint') |
1221 __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint') |
1205 events = ('after_add_entity', 'after_update_entity') |
1222 events = ('after_add_entity', 'after_update_entity') |
1206 |
1223 |
1207 def __call__(self): |
1224 def __call__(self): |
|
1225 if self.entity.cstrtype[0].name == 'SizeConstraint': |
|
1226 txdata = self._cw.transaction_data |
|
1227 if 'newsizecstr' not in txdata: |
|
1228 txdata['newsizecstr'] = set() |
|
1229 txdata['newsizecstr'].add(self.entity) |
1208 CWConstraintAddOp(self._cw, entity=self.entity) |
1230 CWConstraintAddOp(self._cw, entity=self.entity) |
1209 |
1231 |
1210 |
1232 |
1211 class AfterAddConstrainedByHook(SyncSchemaHook): |
1233 class AfterAddConstrainedByHook(SyncSchemaHook): |
1212 __regid__ = 'syncaddconstrainedby' |
1234 __regid__ = 'syncaddconstrainedby' |