mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-26 22:04:56 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1717c63ebc |
@@ -5,12 +5,30 @@ from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
def clamp_applicationconfiguration_integer_fields(apps, schema_editor):
|
||||
# Clamp barcode_dpi, barcode_max_pages, image_dpi and pages because of
|
||||
# PositiveIntegerField --> PositiveSmallIntegerField
|
||||
ApplicationConfiguration = apps.get_model("paperless", "ApplicationConfiguration")
|
||||
ApplicationConfiguration.objects.filter(barcode_dpi__gt=32767).update(
|
||||
barcode_dpi=32767,
|
||||
)
|
||||
ApplicationConfiguration.objects.filter(barcode_max_pages__gt=32767).update(
|
||||
barcode_max_pages=32767,
|
||||
)
|
||||
ApplicationConfiguration.objects.filter(image_dpi__gt=32767).update(image_dpi=32767)
|
||||
ApplicationConfiguration.objects.filter(pages__gt=32767).update(pages=32767)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("paperless", "0006_applicationconfiguration_barcode_tag_split"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
clamp_applicationconfiguration_integer_fields,
|
||||
migrations.RunPython.noop,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_dpi",
|
||||
|
||||
@@ -10,6 +10,24 @@ def clamp_mailrule_maximum_age(apps, schema_editor):
|
||||
MailRule.objects.filter(maximum_age__gt=32767).update(maximum_age=32767)
|
||||
|
||||
|
||||
def clamp_mailrule_order(apps, schema_editor):
|
||||
# The order field of MailRule is only used for relative sorting
|
||||
# (account.rules.order_by("order")), so out-of-range values must be
|
||||
# renumbered by rank rather than clamped to a single value, which
|
||||
# would collapse distinct rules to the same order.
|
||||
MailRule = apps.get_model("paperless_mail", "MailRule")
|
||||
if (
|
||||
MailRule.objects.filter(order__gt=32767).exists()
|
||||
or MailRule.objects.filter(
|
||||
order__lt=-32768,
|
||||
).exists()
|
||||
): # pragma: no cover
|
||||
for index, rule_id in enumerate(
|
||||
MailRule.objects.order_by("order", "pk").values_list("pk", flat=True),
|
||||
):
|
||||
MailRule.objects.filter(pk=rule_id).update(order=index)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
# The data update must commit before PostgreSQL rewrites the table, otherwise
|
||||
# pending foreign-key trigger events can block the subsequent ALTER TABLE.
|
||||
@@ -135,6 +153,10 @@ class Migration(migrations.Migration):
|
||||
verbose_name="maximum age",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
clamp_mailrule_order,
|
||||
migrations.RunPython.noop,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="mailrule",
|
||||
name="order",
|
||||
|
||||
Reference in New Issue
Block a user