mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-12 01:26:47 +01:00
fix the migration history and provide a script to update existing paperless instances to the new version
This commit is contained in:
parent
a2627aa520
commit
d16615bf4b
3 changed files with 95 additions and 1 deletions
37
src/documents/migrations/0023_document_current_filename.py
Normal file
37
src/documents/migrations/0023_document_current_filename.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Generated by Django 2.0.10 on 2019-04-26 18:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def set_filename(apps, schema_editor):
|
||||
Document = apps.get_model("documents", "Document")
|
||||
for doc in Document.objects.all():
|
||||
file_name = "{:07}.{}".format(doc.pk, doc.file_type)
|
||||
if doc.storage_type == "gpg":
|
||||
file_name += ".gpg"
|
||||
|
||||
# Set filename
|
||||
doc.filename = file_name
|
||||
|
||||
# Save document
|
||||
doc.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('documents', '0022_auto_20181007_1420'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='document',
|
||||
name='filename',
|
||||
field=models.FilePathField(default=None,
|
||||
null=True,
|
||||
editable=False,
|
||||
help_text='Current filename in storage',
|
||||
max_length=256),
|
||||
),
|
||||
migrations.RunPython(set_filename, migrations.RunPython.noop)
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue