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

Update migration metadata type and name

parent 4d19cf63
No related branches found
No related tags found
No related merge requests found
......@@ -5,30 +5,34 @@ from django.db.models import Q
def update_balsac_pages(apps, schema_editor):
MetaData = apps.get_model('documents', 'MetaData')
balsac_struct_metadata = MetaData.objects \
balsac_pages_ref_md = 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))
renamed_pages_count = balsac_pages_ref_md.update(name='balsac_id')
print('Renamed {} reference metadata from BALSAC pages'.format(renamed_pages_count))
balsac_ref_metadata = MetaData.objects \
.filter(element__corpus__name__in=('Balsac | S3', 'Balsac | From S3'), name='Reference')
renamed_other_count = balsac_ref_metadata.update(name='balsac_id')
print('Renamed {} reference metadata from all BALSAC elements'.format(renamed_other_count))
def structural_metadata(apps, schema_editor):
def reference_metadata(apps, schema_editor):
"""
Update reference
"""
MetaData = apps.get_model('documents', 'MetaData')
references = MetaData.objects.filter(Q(name='Reference') | Q(name='reference'), type=MetaType.Text)
moved_count = references.update(type=MetaType.Structural)
print('Moved {} reference metadata to Structural type'.format(moved_count))
references = MetaData.objects.filter(name='balsac_id', type=MetaType.Text)
moved_count = references.update(type=MetaType.Reference)
print('Moved {} reference metadata to Reference type'.format(moved_count))
def reverse_migration(apps, schema_editor):
MetaData = apps.get_model('documents', 'MetaData')
MetaData.objects.filter(type=MetaType.Structural).update(type=MetaType.Text)
MetaData.objects.filter(type=MetaType.Reference).update(type=MetaType.Text)
class Migration(migrations.Migration):
......@@ -39,5 +43,5 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(update_balsac_pages, migrations.RunPython.noop),
migrations.RunPython(structural_metadata, reverse_migration)
migrations.RunPython(reference_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