diff --git a/src/documents/migrations/1056_alter_document_transaction_id.py b/src/documents/migrations/1056_alter_document_transaction_id.py new file mode 100644 index 000000000..282dbba74 --- /dev/null +++ b/src/documents/migrations/1056_alter_document_transaction_id.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.1 on 2024-10-26 16:14 + +from django.db import migrations + +import documents.models + + +class Migration(migrations.Migration): + dependencies = [ + ("documents", "1055_alter_storagepath_path"), + ] + + operations = [ + migrations.AlterField( + model_name="document", + name="transaction_id", + field=documents.models.Char32UUIDField(blank=True, null=True), + ), + ] diff --git a/src/documents/models.py b/src/documents/models.py index 37c86305c..6d78aed3e 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -134,6 +134,19 @@ class StoragePath(MatchingModel): verbose_name_plural = _("storage paths") +# see https://docs.djangoproject.com/en/5.1/releases/5.0/#migrating-existing-uuidfield-on-mariadb-10-7 and +# https://github.com/san4ezy/django_softdelete/issues/45 +class Char32UUIDField(models.UUIDField): + def db_type(self, connection): + return "char(32)" + + def get_db_prep_value(self, value, connection, prepared=False): + value = super().get_db_prep_value(value, connection, prepared) + if value is not None and not isinstance(value, str): # pragma: no cover + value = value.hex + return value + + class Document(SoftDeleteModel, ModelWithOwner): STORAGE_TYPE_UNENCRYPTED = "unencrypted" STORAGE_TYPE_GPG = "gpg" @@ -290,6 +303,11 @@ class Document(SoftDeleteModel, ModelWithOwner): ), ) + transaction_id = Char32UUIDField( + blank=True, + null=True, + ) + class Meta: ordering = ("-created",) verbose_name = _("document")