604 lastrel = rset[0][0] == 0 |
604 lastrel = rset[0][0] == 0 |
605 # we have to update physical schema systematically for final and inlined |
605 # we have to update physical schema systematically for final and inlined |
606 # relations, but only if it's the last instance for this relation type |
606 # relations, but only if it's the last instance for this relation type |
607 # for other relations |
607 # for other relations |
608 if (rschema.final or rschema.inlined): |
608 if (rschema.final or rschema.inlined): |
609 rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' |
609 if not cnx.deleted_in_transaction(rdef.subject.eid): |
610 'R eid %%(r)s, X from_entity E, E eid %%(e)s' |
610 rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' |
611 % rdeftype, |
611 'R eid %%(r)s, X from_entity E, E eid %%(e)s' |
612 {'r': rschema.eid, 'e': rdef.subject.eid}) |
612 % rdeftype, |
613 if rset[0][0] == 0 and not cnx.deleted_in_transaction(rdef.subject.eid): |
613 {'r': rschema.eid, 'e': rdef.subject.eid}) |
614 ptypes = cnx.transaction_data.setdefault('pendingrtypes', set()) |
614 if rset[0][0] == 0: |
615 ptypes.add(rschema.type) |
615 ptypes = cnx.transaction_data.setdefault('pendingrtypes', set()) |
616 DropColumn.get_instance(cnx).add_data((str(rdef.subject), str(rschema))) |
616 ptypes.add(rschema.type) |
617 elif rschema.inlined: |
617 DropColumn.get_instance(cnx).add_data((str(rdef.subject), str(rschema))) |
618 cnx.system_sql('UPDATE %s%s SET %s%s=NULL WHERE ' |
618 elif rschema.inlined: |
619 'EXISTS(SELECT 1 FROM entities ' |
619 cnx.system_sql('UPDATE %s%s SET %s%s=NULL WHERE ' |
620 ' WHERE eid=%s%s AND type=%%(to_etype)s)' |
620 'EXISTS(SELECT 1 FROM entities ' |
621 % (SQL_PREFIX, rdef.subject, SQL_PREFIX, rdef.rtype, |
621 ' WHERE eid=%s%s AND type=%%(to_etype)s)' |
622 SQL_PREFIX, rdef.rtype), |
622 % (SQL_PREFIX, rdef.subject, SQL_PREFIX, rdef.rtype, |
623 {'to_etype': rdef.object.type}) |
623 SQL_PREFIX, rdef.rtype), |
|
624 {'to_etype': rdef.object.type}) |
624 elif lastrel: |
625 elif lastrel: |
625 DropRelationTable(cnx, str(rschema)) |
626 DropRelationTable(cnx, str(rschema)) |
626 else: |
627 else: |
627 cnx.system_sql('DELETE FROM %s_relation WHERE ' |
628 cnx.system_sql('DELETE FROM %s_relation WHERE ' |
628 'EXISTS(SELECT 1 FROM entities ' |
629 'EXISTS(SELECT 1 FROM entities ' |