mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	validate move before migration
This commit is contained in:
		
							parent
							
								
									1e5a418191
								
							
						
					
					
						commit
						0ed001c56e
					
				@ -74,12 +74,18 @@ def move_old_to_new_locations(apps, schema_editor):
 | 
			
		||||
    # check for documents that have incorrect archive versions
 | 
			
		||||
    for 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])
 | 
			
		||||
 | 
			
		||||
@ -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 migration
 | 
			
		||||
        sanity_check()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user