Skip to content
Snippets Groups Projects
Commit 412ff37d authored by ml bonhomme's avatar ml bonhomme :bee:
Browse files

Set process.element to null on corpus processes before corpus deletion

parent c76fdeeb
No related branches found
No related tags found
1 merge request!2303Set process.element to null on corpus processes before corpus deletion
......@@ -41,6 +41,10 @@ def corpus_delete(corpus_id: str) -> None:
corpus.top_level_type_id = None
corpus.save(update_fields=["top_level_type_id"])
# Set process.element to NULL in all processes, to avoid IntegrityErrors when deleting elements, as
# elements are deleted before processes.
Process.objects.filter(corpus_id=corpus_id).exclude(element_id=None).update(element_id=None)
# Delete all related objects, bypassing RESTRICTs deletion rules
# and Django's way of loading everything into memory before deleting.
querysets = [
......
......@@ -10,6 +10,11 @@ FROM "documents_corpus"
WHERE "documents_corpus"."id" = '{corpus_id}'::uuid
LIMIT 21;
UPDATE "process_process"
SET "element_id" = NULL
WHERE ("process_process"."corpus_id" = '{corpus_id}'::uuid
AND NOT ("process_process"."element_id" IS NULL));
SELECT "django_content_type"."id",
"django_content_type"."app_label",
"django_content_type"."model"
......
......@@ -14,6 +14,11 @@ UPDATE "documents_corpus"
SET "top_level_type_id" = NULL
WHERE "documents_corpus"."id" = '{corpus_id}'::uuid;
UPDATE "process_process"
SET "element_id" = NULL
WHERE ("process_process"."corpus_id" = '{corpus_id}'::uuid
AND NOT ("process_process"."element_id" IS NULL));
SELECT "django_content_type"."id",
"django_content_type"."app_label",
"django_content_type"."model"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment