mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-20 17:44:56 -05:00
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
# Generated by Django 5.1.7 on 2025-04-04 01:08
|
|
|
|
|
|
import datetime
|
|
|
|
from django.db import migrations
|
|
from django.db import models
|
|
from django.db.models.functions import TruncDate
|
|
|
|
|
|
def migrate_date(apps, schema_editor):
|
|
Document = apps.get_model("documents", "Document")
|
|
queryset = Document.objects.annotate(
|
|
truncated_created=TruncDate("created"),
|
|
).values("id", "truncated_created")
|
|
|
|
# Batch to avoid loading all objects into memory at once,
|
|
# which would be problematic for large datasets.
|
|
batch_size = 500
|
|
updates = []
|
|
for item in queryset.iterator(chunk_size=batch_size):
|
|
updates.append(
|
|
Document(id=item["id"], created_date=item["truncated_created"]),
|
|
)
|
|
if len(updates) >= batch_size:
|
|
Document.objects.bulk_update(updates, ["created_date"])
|
|
updates.clear()
|
|
if updates:
|
|
Document.objects.bulk_update(updates, ["created_date"])
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("documents", "1066_alter_workflowtrigger_schedule_offset_days"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name="document",
|
|
name="created_date",
|
|
field=models.DateField(null=True),
|
|
),
|
|
migrations.RunPython(migrate_date, reverse_code=migrations.RunPython.noop),
|
|
migrations.RemoveField(
|
|
model_name="document",
|
|
name="created",
|
|
),
|
|
migrations.RenameField(
|
|
model_name="document",
|
|
old_name="created_date",
|
|
new_name="created",
|
|
),
|
|
migrations.AlterField(
|
|
model_name="document",
|
|
name="created",
|
|
field=models.DateField(
|
|
db_index=True,
|
|
default=datetime.datetime.today,
|
|
verbose_name="created",
|
|
),
|
|
),
|
|
]
|