🩹(migration) add migration to update default titles

The frontend was setting a default titles for
documents with empty titles.
This migration updates the document table to set
the title to null instead of the default title.
We add a test to ensure that the migration
works as expected.
This commit is contained in:
Anthony LC
2025-02-12 12:24:29 +01:00
committed by Anthony LC
parent 7da7214afb
commit 6cc20aeacb
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from django.db import migrations
def update_titles_to_null(apps, schema_editor):
"""
If the titles are "Untitled document" or "Unbenanntes Dokument" or "Document sans titre"
we set them to Null
"""
Document = apps.get_model("core", "Document")
Document.objects.filter(
title__in=["Untitled document", "Unbenanntes Dokument", "Document sans titre"]
).update(title=None)
class Migration(migrations.Migration):
dependencies = [
("core", "0017_add_fields_for_soft_delete"),
]
operations = [
migrations.RunPython(
update_titles_to_null,
reverse_code=migrations.RunPython.noop
),
]