Finalizes the migration
This commit is contained in:
parent
1798b767d6
commit
63f78658ed
@ -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 migrations
|
||||||
|
from django.db import models
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
|
|
||||||
@ -20,13 +20,17 @@ def convert_from_format_to_template(apps, schema_editor):
|
|||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
("documents", "1053_document_page_count"),
|
("documents", "1054_customfieldinstance_value_monetary_amount_and_more"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="storagepath",
|
||||||
|
name="path",
|
||||||
|
field=models.CharField(max_length=2048, verbose_name="path"),
|
||||||
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
convert_from_format_to_template,
|
convert_from_format_to_template,
|
||||||
# This is a one way migration
|
|
||||||
migrations.RunPython.noop,
|
migrations.RunPython.noop,
|
||||||
),
|
),
|
||||||
]
|
]
|
@ -127,7 +127,7 @@ class DocumentType(MatchingModel):
|
|||||||
class StoragePath(MatchingModel):
|
class StoragePath(MatchingModel):
|
||||||
path = models.CharField(
|
path = models.CharField(
|
||||||
_("path"),
|
_("path"),
|
||||||
max_length=512,
|
max_length=2048,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(MatchingModel.Meta):
|
class Meta(MatchingModel.Meta):
|
||||||
|
30
src/documents/tests/test_migration_storage_path_template.py
Normal file
30
src/documents/tests/test_migration_storage_path_template.py
Normal 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")
|
Loading…
x
Reference in New Issue
Block a user