mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	validate move before migration
This commit is contained in:
		| @@ -74,12 +74,18 @@ def move_old_to_new_locations(apps, schema_editor): | |||||||
|     # check for documents that have incorrect archive versions |     # check for documents that have incorrect archive versions | ||||||
|     for doc in Document.objects.filter(archive_checksum__isnull=False): |     for doc in Document.objects.filter(archive_checksum__isnull=False): | ||||||
|         old_path = archive_path_old(doc) |         old_path = archive_path_old(doc) | ||||||
|  |         new_path = archive_path_new(doc) | ||||||
|  |  | ||||||
|         if not os.path.isfile(old_path): |         if not os.path.isfile(old_path): | ||||||
|             raise ValueError( |             raise ValueError( | ||||||
|                 f"Archived document of {doc.filename} does not exist at: " |                 f"Archived document of {doc.filename} does not exist at: " | ||||||
|                 f"{old_path}") |                 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: |         if old_path in old_archive_path_to_id: | ||||||
|             affected_document_ids.add(doc.id) |             affected_document_ids.add(doc.id) | ||||||
|             affected_document_ids.add(old_archive_path_to_id[old_path]) |             affected_document_ids.add(old_archive_path_to_id[old_path]) | ||||||
|   | |||||||
| @@ -141,6 +141,8 @@ class TestMigrateArchiveFiles(DirectoriesMixin, TestMigrations): | |||||||
|                     archive_checksum = hashlib.md5(f.read()).hexdigest() |                     archive_checksum = hashlib.md5(f.read()).hexdigest() | ||||||
|                 self.assertEqual(archive_checksum, doc.archive_checksum) |                 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 migration |         # this will raise errors when any inconsistencies remain after migration | ||||||
|         sanity_check() |         sanity_check() | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler