944 % (rtype, new.eid, oldeid), ask_confirm=False) |
944 % (rtype, new.eid, oldeid), ask_confirm=False) |
945 # delete relations using SQL to avoid relations content removal |
945 # delete relations using SQL to avoid relations content removal |
946 # triggered by schema synchronization hooks. |
946 # triggered by schema synchronization hooks. |
947 session = self.session |
947 session = self.session |
948 for rdeftype in ('CWRelation', 'CWAttribute'): |
948 for rdeftype in ('CWRelation', 'CWAttribute'): |
949 thispending = set() |
949 thispending = set( (eid for eid, in self.sqlexec( |
950 for eid, in self.sqlexec('SELECT cw_eid FROM cw_%s ' |
950 'SELECT cw_eid FROM cw_%s WHERE cw_from_entity=%%(eid)s OR ' |
951 'WHERE cw_from_entity=%%(eid)s OR ' |
951 ' cw_to_entity=%%(eid)s' % rdeftype, |
952 ' cw_to_entity=%%(eid)s' % rdeftype, |
952 {'eid': oldeid}, ask_confirm=False)) ) |
953 {'eid': oldeid}, ask_confirm=False): |
953 # we should add deleted eids into pending eids else we may |
954 # we should add deleted eids into pending eids else we may |
954 # get some validation error on commit since integrity hooks |
955 # get some validation error on commit since integrity hooks |
955 # may think some required relation is missing... This also ensure |
956 # may think some required relation is missing... This also ensure |
956 # repository caches are properly cleanup |
957 # repository caches are properly cleanup |
957 hook.CleanupDeletedEidsCacheOp.get_instance(session).union(thispending) |
958 hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(eid) |
958 # and don't forget to remove record from system tables |
959 # and don't forget to remove record from system tables |
959 entities = [session.entity_from_eid(eid, rdeftype) for eid in thispending] |
960 self.repo.system_source.delete_info( |
960 self.repo.system_source.delete_info_multi(session, entities, 'system') |
961 session, session.entity_from_eid(eid, rdeftype), |
961 self.sqlexec('DELETE FROM cw_%s WHERE cw_from_entity=%%(eid)s OR ' |
962 'system', None) |
|
963 thispending.add(eid) |
|
964 self.sqlexec('DELETE FROM cw_%s ' |
|
965 'WHERE cw_from_entity=%%(eid)s OR ' |
|
966 'cw_to_entity=%%(eid)s' % rdeftype, |
962 'cw_to_entity=%%(eid)s' % rdeftype, |
967 {'eid': oldeid}, ask_confirm=False) |
963 {'eid': oldeid}, ask_confirm=False) |
968 # now we have to manually cleanup relations pointing to deleted |
964 # now we have to manually cleanup relations pointing to deleted |
969 # entities |
965 # entities |
970 thiseids = ','.join(str(eid) for eid in thispending) |
966 thiseids = ','.join(str(eid) for eid in thispending) |
1141 self._synchronize_eschema(erschema, syncrdefs=syncrdefs, |
1137 self._synchronize_eschema(erschema, syncrdefs=syncrdefs, |
1142 syncperms=syncperms, |
1138 syncperms=syncperms, |
1143 syncprops=syncprops) |
1139 syncprops=syncprops) |
1144 else: |
1140 else: |
1145 for etype in self.repo.schema.entities(): |
1141 for etype in self.repo.schema.entities(): |
|
1142 if etype.eid is None: |
|
1143 # not yet added final etype (thing to BigInt defined in |
|
1144 # yams though 3.13 migration not done yet) |
|
1145 continue |
1146 self._synchronize_eschema(etype, syncrdefs=syncrdefs, |
1146 self._synchronize_eschema(etype, syncrdefs=syncrdefs, |
1147 syncprops=syncprops, syncperms=syncperms) |
1147 syncprops=syncprops, syncperms=syncperms) |
1148 if commit: |
1148 if commit: |
1149 self.commit() |
1149 self.commit() |
1150 |
1150 |