mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	making the migration reversible
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| # Generated by Django 3.1.3 on 2020-11-20 11:21 | ||||
| import mimetypes | ||||
| import os | ||||
|  | ||||
| import magic | ||||
| @@ -29,6 +30,15 @@ def add_mime_types(apps, schema_editor): | ||||
|         d.save() | ||||
|  | ||||
|  | ||||
| def add_file_extensions(apps, schema_editor): | ||||
|     Document = apps.get_model("documents", "Document") | ||||
|     documents = Document.objects.all() | ||||
|  | ||||
|     for d in documents: | ||||
|         d.file_type = os.path.splitext(d.filename)[1].strip('.') | ||||
|         d.save() | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
| @@ -42,7 +52,24 @@ class Migration(migrations.Migration): | ||||
|             field=models.CharField(default="-", editable=False, max_length=256), | ||||
|             preserve_default=False, | ||||
|         ), | ||||
|         migrations.RunPython(add_mime_types), | ||||
|         migrations.RunPython(add_mime_types, migrations.RunPython.noop), | ||||
|  | ||||
|         # This operation is here so that we can revert the entire migration: | ||||
|         # By allowing this field to be blank and null, we can revert the | ||||
|         # remove operation further down and the database won't complain about | ||||
|         # NOT NULL violations. | ||||
|         migrations.AlterField( | ||||
|             model_name='document', | ||||
|             name='file_type', | ||||
|             field=models.CharField( | ||||
|                 choices=[('pdf', 'PDF'), ('png', 'PNG'), ('jpg', 'JPG'), ('gif', 'GIF'), ('tiff', 'TIFF'), ('txt', 'TXT'), ('csv', 'CSV'), ('md', 'MD')], | ||||
|                 editable=False, | ||||
|                 max_length=4, | ||||
|                 null=True, | ||||
|                 blank=True | ||||
|             ), | ||||
|         ), | ||||
|         migrations.RunPython(migrations.RunPython.noop, add_file_extensions), | ||||
|         migrations.RemoveField( | ||||
|             model_name='document', | ||||
|             name='file_type', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonas Winkler
					Jonas Winkler