From aa7012963b4025e055f54456bfb9f12c0847cc09 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 7 Sep 2023 11:43:34 +0100 Subject: [PATCH] Use new migration rather than modifying existing in place This won't change the impact, but ensures deployments definitely have a reset counter, even if they've already released 5.0. --- .../migrations/0004_copy_queries.py | 17 ---------- .../migrations/0006_reset_query_sequence.py | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 wagtail/contrib/search_promotions/migrations/0006_reset_query_sequence.py diff --git a/wagtail/contrib/search_promotions/migrations/0004_copy_queries.py b/wagtail/contrib/search_promotions/migrations/0004_copy_queries.py index 0f15ca203b..31a7bfa034 100644 --- a/wagtail/contrib/search_promotions/migrations/0004_copy_queries.py +++ b/wagtail/contrib/search_promotions/migrations/0004_copy_queries.py @@ -1,18 +1,6 @@ # 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): @@ -39,9 +27,4 @@ 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 - ), ] diff --git a/wagtail/contrib/search_promotions/migrations/0006_reset_query_sequence.py b/wagtail/contrib/search_promotions/migrations/0006_reset_query_sequence.py new file mode 100644 index 0000000000..7745c583b8 --- /dev/null +++ b/wagtail/contrib/search_promotions/migrations/0006_reset_query_sequence.py @@ -0,0 +1,31 @@ +# Generated by Django 4.0.10 on 2023-09-07 10:41 + +from django.db import migrations +from django.core.management.color import no_style + + +def reset_search_promotion_sequence(apps, schema_editor): + """ + We set an explicit pk instead of relying on auto-incrementation in migration 0004, + so we need to reset the database sequence. + """ + 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): + dependencies = [ + ("wagtailsearchpromotions", "0005_switch_query_model"), + ] + + operations = [ + migrations.RunPython( + reset_search_promotion_sequence, migrations.RunPython.noop + ), + ]