703 self.size_cstr_changed = True |
703 self.size_cstr_changed = True |
704 elif cstrtype == 'UniqueConstraint' and oldcstr is None: |
704 elif cstrtype == 'UniqueConstraint' and oldcstr is None: |
705 syssource.update_rdef_unique(session, rdef) |
705 syssource.update_rdef_unique(session, rdef) |
706 self.unique_changed = True |
706 self.unique_changed = True |
707 |
707 |
|
708 |
708 class CWUniqueTogetherConstraintAddOp(MemSchemaOperation): |
709 class CWUniqueTogetherConstraintAddOp(MemSchemaOperation): |
709 entity = None # make pylint happy |
710 entity = None # make pylint happy |
710 def precommit_event(self): |
711 def precommit_event(self): |
711 session = self.session |
712 session = self.session |
712 prefix = SQL_PREFIX |
713 prefix = SQL_PREFIX |
713 table = '%s%s' % (prefix, self.entity.constraint_of[0].name) |
714 table = '%s%s' % (prefix, self.entity.constraint_of[0].name) |
714 cols = ['%s%s' % (prefix, r.rtype.name) |
715 cols = ['%s%s' % (prefix, r.name) for r in self.entity.relations] |
715 for r in self.entity.relations] |
|
716 dbhelper= session.pool.source('system').dbhelper |
716 dbhelper= session.pool.source('system').dbhelper |
717 sqls = dbhelper.sqls_create_multicol_unique_index(table, cols) |
717 sqls = dbhelper.sqls_create_multicol_unique_index(table, cols) |
718 for sql in sqls: |
718 for sql in sqls: |
719 session.system_sql(sql) |
719 session.system_sql(sql) |
720 |
720 |
721 # XXX revertprecommit_event |
721 # XXX revertprecommit_event |
722 |
722 |
723 def postcommit_event(self): |
723 def postcommit_event(self): |
724 eschema = self.session.vreg.schema.schema_by_eid(self.entity.constraint_of[0].eid) |
724 eschema = self.session.vreg.schema.schema_by_eid(self.entity.constraint_of[0].eid) |
725 attrs = [r.rtype.name for r in self.entity.relations] |
725 attrs = [r.name for r in self.entity.relations] |
726 eschema._unique_together.append(attrs) |
726 eschema._unique_together.append(attrs) |
|
727 |
727 |
728 |
728 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation): |
729 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation): |
729 entity = oldcstr = None # for pylint |
730 entity = oldcstr = None # for pylint |
730 cols = [] # for pylint |
731 cols = [] # for pylint |
731 def precommit_event(self): |
732 def precommit_event(self): |
744 eschema = self.session.vreg.schema.schema_by_eid(self.entity.eid) |
745 eschema = self.session.vreg.schema.schema_by_eid(self.entity.eid) |
745 cols = set(self.cols) |
746 cols = set(self.cols) |
746 unique_together = [ut for ut in eschema._unique_together |
747 unique_together = [ut for ut in eschema._unique_together |
747 if set(ut) != cols] |
748 if set(ut) != cols] |
748 eschema._unique_together = unique_together |
749 eschema._unique_together = unique_together |
|
750 |
749 |
751 |
750 # operations for in-memory schema synchronization ############################# |
752 # operations for in-memory schema synchronization ############################# |
751 |
753 |
752 class MemSchemaCWETypeDel(MemSchemaOperation): |
754 class MemSchemaCWETypeDel(MemSchemaOperation): |
753 """actually remove the entity type from the instance's schema""" |
755 """actually remove the entity type from the instance's schema""" |
1140 if self._cw.deleted_in_transaction(self.eidto): |
1142 if self._cw.deleted_in_transaction(self.eidto): |
1141 return |
1143 return |
1142 schema = self._cw.vreg.schema |
1144 schema = self._cw.vreg.schema |
1143 cstr = self._cw.entity_from_eid(self.eidfrom) |
1145 cstr = self._cw.entity_from_eid(self.eidfrom) |
1144 entity = schema.schema_by_eid(self.eidto) |
1146 entity = schema.schema_by_eid(self.eidto) |
1145 cols = [r.rtype.name |
1147 cols = [r.name for r in cstr.relations] |
1146 for r in cstr.relations] |
1148 CWUniqueTogetherConstraintDelOp(self._cw, entity=entity, |
1147 CWUniqueTogetherConstraintDelOp(self._cw, entity=entity, oldcstr=cstr, cols=cols) |
1149 oldcstr=cstr, cols=cols) |
1148 |
1150 |
1149 |
1151 |
1150 # permissions synchronization hooks ############################################ |
1152 # permissions synchronization hooks ############################################ |
1151 |
1153 |
1152 class AfterAddPermissionHook(SyncSchemaHook): |
1154 class AfterAddPermissionHook(SyncSchemaHook): |