mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-21 00:48:32 +00:00
Fix: fix broken migration in 3.0.1 (#13242)
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user