A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
validate move before migration
jonaswinkler0ed001c56ee5
diff --git a/src/documents/migrations/1012_fix_archive_files.py b/src/documents/migrations/1012_fix_archive_files.pyindex ab7e88a6a..f75ae431d 100644--- a/src/documents/migrations/1012_fix_archive_files.py+++ b/src/documents/migrations/1012_fix_archive_files.py@@ -74,12 +74,18 @@ def move_old_to_new_locations(apps, schema_editor):# check for documents that have incorrect archive versionsfor doc in Document.objects.filter(archive_checksum__isnull=False):old_path = archive_path_old(doc)+ new_path = archive_path_new(doc)if not os.path.isfile(old_path):raise ValueError(f"Archived document of {doc.filename} does not exist at: "f"{old_path}")+ if old_path != new_path and os.path.isfile(new_path):+ raise ValueError(+ f"Need to move {old_path} to {new_path}, but target file "+ f"already exists")+if old_path in old_archive_path_to_id:affected_document_ids.add(doc.id)affected_document_ids.add(old_archive_path_to_id[old_path])diff --git a/src/documents/tests/test_migration_archive_files.py b/src/documents/tests/test_migration_archive_files.pyindex 5970a83eb..69c1b51eb 100644--- a/src/documents/tests/test_migration_archive_files.py+++ b/src/documents/tests/test_migration_archive_files.py@@ -141,6 +141,8 @@ class TestMigrateArchiveFiles(DirectoriesMixin, TestMigrations):archive_checksum = hashlib.md5(f.read()).hexdigest()self.assertEqual(archive_checksum, doc.archive_checksum)+ self.assertEqual(Document.objects.filter(archive_checksum__isnull=False).count(), 4)+# this will raise errors when any inconsistencies remain after migrationsanity_check()