mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00

The documents.tests.test_migration_mime_type test suite failes if no backwards migration is provided. This simple backwards migration sets the old assign_tag field with a tag if exactly one is set in assign_tags.
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# Generated by Django 3.2.12 on 2022-03-11 15:02
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
def migrate_tag_to_tags(apps, schema_editor):
|
|
# Manual data migration, see
|
|
# https://docs.djangoproject.com/en/3.2/topics/migrations/#data-migrations
|
|
#
|
|
# Copy the assign_tag property to the new assign_tags set if it exists.
|
|
MailRule = apps.get_model("paperless_mail", "MailRule")
|
|
for mail_rule in MailRule.objects.all():
|
|
if mail_rule.assign_tag:
|
|
mail_rule.assign_tags.add(mail_rule.assign_tag)
|
|
mail_rule.save()
|
|
|
|
|
|
def migrate_tags_to_tag(apps, schema_editor):
|
|
# Manual data migration, see
|
|
# https://docs.djangoproject.com/en/3.2/topics/migrations/#data-migrations
|
|
#
|
|
# Copy the unique value in the assign_tags set to the old assign_tag property.
|
|
# Do nothing if the tag is not unique.
|
|
MailRule = apps.get_model("paperless_mail", "MailRule")
|
|
for mail_rule in MailRule.objects.all():
|
|
tags = mail_rule.assign_tags.all()
|
|
if len(tags) == 1:
|
|
mail_rule.assign_tag = tags[0]
|
|
mail_rule.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("paperless_mail", "0009_mailrule_assign_tags"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(migrate_tag_to_tags, migrate_tags_to_tag),
|
|
]
|