Finalizes the migration

This commit is contained in:
Trenton H 2024-10-03 08:54:33 -07:00
parent 1798b767d6
commit 63f78658ed
3 changed files with 39 additions and 5 deletions

View File

@ -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,
),
]

View File

@ -127,7 +127,7 @@ class DocumentType(MatchingModel):
class StoragePath(MatchingModel):
path = models.CharField(
_("path"),
max_length=512,
max_length=2048,
)
class Meta(MatchingModel.Meta):

View File

@ -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")