Fix: fix broken migration in 3.0.1 (#13242)

This commit is contained in:
shamoon
2026-07-23 17:59:03 -07:00
committed by GitHub
parent 5569447ea0
commit 371c4f57d3
3 changed files with 52 additions and 28 deletions
@@ -1,27 +0,0 @@
# Split out of 0002_optimize_integer_field_sizes.py into its own migration
# (own transaction). Running this UPDATE in the same transaction as the
# later ALTER TABLE on paperless_mail_mailrule can fail on PostgreSQL with
# "cannot ALTER TABLE because it has pending trigger events", since the
# update queues FK trigger events against that table that are still pending
# when the subsequent AlterField tries to rewrite it. Committing the clamp
# here first avoids that.
from django.db import migrations
def clamp_mailrule_maximum_age(apps, schema_editor):
# Clamp the maximum_age field of MailRule because of PositiveIntegerField --> PositiveSmallIntegerField
MailRule = apps.get_model("paperless_mail", "MailRule")
MailRule.objects.filter(maximum_age__gt=32767).update(maximum_age=32767)
class Migration(migrations.Migration):
dependencies = [
("paperless_mail", "0001_squashed"),
]
operations = [
migrations.RunPython(
clamp_mailrule_maximum_age,
migrations.RunPython.noop,
),
]
@@ -4,9 +4,19 @@ from django.db import migrations
from django.db import models
def clamp_mailrule_maximum_age(apps, schema_editor):
# Clamp the maximum_age field of MailRule because of PositiveIntegerField --> PositiveSmallIntegerField
MailRule = apps.get_model("paperless_mail", "MailRule")
MailRule.objects.filter(maximum_age__gt=32767).update(maximum_age=32767)
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.
atomic = False
dependencies = [
("paperless_mail", "0001_1_clamp_mailrule_maximum_age"),
("paperless_mail", "0001_squashed"),
]
operations = [
@@ -112,6 +122,10 @@ class Migration(migrations.Migration):
verbose_name="consumption scope",
),
),
migrations.RunPython(
clamp_mailrule_maximum_age,
migrations.RunPython.noop,
),
migrations.AlterField(
model_name="mailrule",
name="maximum_age",