From 63f78658ed725d86b1d33e20b833b9989ca32d48 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Thu, 3 Oct 2024 08:54:33 -0700 Subject: [PATCH] Finalizes the migration --- ...ates.py => 1055_alter_storagepath_path.py} | 12 +++++--- src/documents/models.py | 2 +- .../test_migration_storage_path_template.py | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) rename src/documents/migrations/{1054_alter_storage_path_templates.py => 1055_alter_storagepath_path.py} (70%) create mode 100644 src/documents/tests/test_migration_storage_path_template.py diff --git a/src/documents/migrations/1054_alter_storage_path_templates.py b/src/documents/migrations/1055_alter_storagepath_path.py similarity index 70% rename from src/documents/migrations/1054_alter_storage_path_templates.py rename to src/documents/migrations/1055_alter_storagepath_path.py index 796e00b87..ca3d05d41 100644 --- a/src/documents/migrations/1054_alter_storage_path_templates.py +++ b/src/documents/migrations/1055_alter_storagepath_path.py @@ -1,7 +1,7 @@ -# Generated by Django 5.1.1 on 2024-10-01 20:42 - +# Generated by Django 5.1.1 on 2024-10-03 14:47 from django.db import migrations +from django.db import models from django.db import transaction @@ -20,13 +20,17 @@ def convert_from_format_to_template(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ("documents", "1053_document_page_count"), + ("documents", "1054_customfieldinstance_value_monetary_amount_and_more"), ] operations = [ + migrations.AlterField( + model_name="storagepath", + name="path", + field=models.CharField(max_length=2048, verbose_name="path"), + ), migrations.RunPython( convert_from_format_to_template, - # This is a one way migration migrations.RunPython.noop, ), ] diff --git a/src/documents/models.py b/src/documents/models.py index 80476bffa..23325739c 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -127,7 +127,7 @@ class DocumentType(MatchingModel): class StoragePath(MatchingModel): path = models.CharField( _("path"), - max_length=512, + max_length=2048, ) class Meta(MatchingModel.Meta): diff --git a/src/documents/tests/test_migration_storage_path_template.py b/src/documents/tests/test_migration_storage_path_template.py new file mode 100644 index 000000000..37b87a115 --- /dev/null +++ b/src/documents/tests/test_migration_storage_path_template.py @@ -0,0 +1,30 @@ +from documents.models import StoragePath +from documents.tests.utils import TestMigrations + + +class TestMigrateStoragePathToTemplate(TestMigrations): + migrate_from = "1054_customfieldinstance_value_monetary_amount_and_more" + migrate_to = "1055_alter_storagepath_path" + + def setUpBeforeMigration(self, apps): + self.old_format = StoragePath.objects.create( + name="sp1", + path="Something/{title}", + ) + self.new_format = StoragePath.objects.create( + name="sp2", + path="{{asn}}/{{title}}", + ) + self.no_formatting = StoragePath.objects.create( + name="sp3", + path="Some/Fixed/Path", + ) + + def test_migrate_old_to_new_storage_path(self): + self.old_format.refresh_from_db() + self.new_format.refresh_from_db() + self.no_formatting.refresh_from_db() + + self.assertEqual(self.old_format.path, "Something/{{ title }}") + self.assertEqual(self.new_format.path, "{{asn}}/{{title}}") + self.assertEqual(self.no_formatting.path, "Some/Fixed/Path")