Reset search promotions sequence after copying table content

We insert values manually, including an explicit pk, but don't ensure the sequence is set to a value higher than the largest pk.

See also https://code.djangoproject.com/ticket/17415
stable/5.1.x
Jake Howard 2023-08-31 15:53:47 +01:00 zatwierdzone przez Matt Westcott
rodzic 587fb4d176
commit bb2ebf94cf
1 zmienionych plików z 17 dodań i 0 usunięć
wagtail/contrib/search_promotions/migrations

Wyświetl plik

@ -1,6 +1,18 @@
# Generated by Django 3.1.8 on 2021-06-22 14:56
from django.db import migrations
from django.core.management.color import no_style
def reset_search_promotion_sequence(apps, schema_editor):
Query = apps.get_model("wagtailsearchpromotions.Query")
QueryDailyHits = apps.get_model("wagtailsearchpromotions.QueryDailyHits")
statements = schema_editor.connection.ops.sequence_reset_sql(
no_style(), [Query, QueryDailyHits]
)
for statement in statements:
schema_editor.execute(statement)
class Migration(migrations.Migration):
@ -27,4 +39,9 @@ class Migration(migrations.Migration):
""",
"",
),
# We set an explicit pk instead of relying on auto-incrementation,
# so we need to reset the database sequence.
migrations.RunPython(
reset_search_promotion_sequence, migrations.RunPython.noop
),
]