🩹(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:
25
src/backend/core/migrations/0018_update_blank_title.py
Normal file
25
src/backend/core/migrations/0018_update_blank_title.py
Normal 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
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user