Skip to content
Snippets Groups Projects
Commit ce30e533 authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Handle BALSAC data in migration

parent d63e292c
No related branches found
No related tags found
No related merge requests found
from django.db import migrations
from arkindex_common.enums import MetaType
from django.db.models import Q
def update_balsac_pages(apps, schema_editor):
MetaData = apps.get_model('documents', 'MetaData')
balsac_struct_metadata = MetaData.objects \
.filter(
element__corpus__name__in=('Balsac | S3', 'Balsac | From S3'),
element__type__slug='page'
).filter(
Q(name="name") | Q(name="filename")
)
renamed_count = balsac_struct_metadata.update(name='Reference')
print('Renamed {} metadata from BALSAC corpora'.format(renamed_count))
def structure_metadata(apps, schema_editor):
......@@ -7,7 +21,9 @@ def structure_metadata(apps, schema_editor):
Update reference
"""
MetaData = apps.get_model('documents', 'MetaData')
MetaData.objects.filter(name='Reference').update(type=MetaType.Structure)
references = MetaData.objects.filter(Q(name='Reference') | Q(name='reference'), type=MetaType.Text)
moved_count = references.update(type=MetaType.Structure)
print('Moved {} reference metadata to Structure type'.format(moved_count))
def reverse_migration(apps, schema_editor):
......@@ -22,5 +38,6 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_balsac_pages, migrations.RunPython.noop),
migrations.RunPython(structure_metadata, reverse_migration)
]
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