diff --git a/wagtail/contrib/search_promotions/migrations/0001_initial.py b/wagtail/contrib/search_promotions/migrations/0001_initial.py index 396e4b431e..8ab2ed15f9 100644 --- a/wagtail/contrib/search_promotions/migrations/0001_initial.py +++ b/wagtail/contrib/search_promotions/migrations/0001_initial.py @@ -1,5 +1,7 @@ -# -*- coding: utf-8 -*- +# Generated by Django 4.0.7 on 2022-10-10 17:43 + from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -10,61 +12,46 @@ class Migration(migrations.Migration): ] operations = [ - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.CreateModel( - name="EditorsPick", - fields=[ - ( - "id", - models.AutoField( - primary_key=True, - serialize=False, - verbose_name="ID", - auto_created=True, - ), - ), - ( - "sort_order", - models.IntegerField(editable=False, null=True, blank=True), - ), - ( - "description", - models.TextField(verbose_name="Description", blank=True), - ), - ( - "page", - models.ForeignKey( - on_delete=models.CASCADE, - verbose_name="Page", - to="wagtailcore.Page", - ), - ), - ( - "query", - models.ForeignKey( - on_delete=models.CASCADE, - to="wagtailsearch.Query", - related_name="editors_picks", - ), - ), - ], - options={ - "db_table": "wagtailsearch_editorspick", - "verbose_name": "Editor's Pick", - "ordering": ("sort_order",), - }, + migrations.CreateModel( + name="SearchPromotion", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "sort_order", + models.IntegerField(blank=True, editable=False, null=True), + ), + ( + "description", + models.TextField(blank=True, verbose_name="description"), + ), + ( + "page", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="wagtailcore.page", + verbose_name="page", + ), + ), + ( + "query", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="editors_picks", + to="wagtailsearch.query", + ), ), ], - database_operations=[], - ), - migrations.AlterModelTable( - name="editorspick", - table=None, - ), - migrations.RenameModel(old_name="EditorsPick", new_name="SearchPromotion"), - migrations.AlterModelOptions( - name="searchpromotion", - options={"ordering": ("sort_order",), "verbose_name": "Search promotion"}, + options={ + "verbose_name": "Search promotion", + "ordering": ("sort_order",), + }, ), ] diff --git a/wagtail/search/migrations/0003_remove_editors_pick.py b/wagtail/search/migrations/0003_remove_editors_pick.py index 67fb9c921d..fae29dc8f4 100644 --- a/wagtail/search/migrations/0003_remove_editors_pick.py +++ b/wagtail/search/migrations/0003_remove_editors_pick.py @@ -8,27 +8,10 @@ class Migration(migrations.Migration): ] operations = [ - # EditorsPicks have been moved to the "wagtailsearchpromotions" module. - # Remove EditorsPick from wagtailsearch but don't drop the underlying table - # so wagtailsearchpromotions can pick it up in its initial migration. - # If wagtailsearchpromotions isn't installed, this table will remain - # in the database unmanaged until it is. This could potentially happen - # at any point in the future so it's important to keep this behaviour - # even if we decide to squash these migrations. - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.RemoveField( - model_name="editorspick", - name="page", - ), - migrations.RemoveField( - model_name="editorspick", - name="query", - ), - migrations.DeleteModel( - name="EditorsPick", - ), - ], - database_operations=[], - ) + # Do nothing. Previously this migration dropped the EditorsPick model from the application + # state but kept the database intact so that the wagtail.contrib.search_promotions app + # could subsequently adopt it by renaming the table. wagtail.contrib.search_promotions + # now creates its own table, so we don't want to keep the table from wagtailsearch around; + # we will delete it properly in wagtailsearch migration 0007. + # See https://github.com/wagtail/wagtail/issues/1824#issuecomment-1271840741 ] diff --git a/wagtail/search/migrations/0007_delete_editorspick.py b/wagtail/search/migrations/0007_delete_editorspick.py new file mode 100644 index 0000000000..76da71e2d8 --- /dev/null +++ b/wagtail/search/migrations/0007_delete_editorspick.py @@ -0,0 +1,24 @@ +# Generated by Django 4.0.7 on 2022-10-10 17:53 + +from django.db import migrations + + +class DeleteModelIfExists(migrations.DeleteModel): + def database_forwards(self, app_label, schema_editor, from_state, to_state): + model = from_state.apps.get_model(app_label, self.name) + table_name = model._meta.db_table + if table_name in schema_editor.connection.introspection.table_names(): + super().database_forwards(app_label, schema_editor, from_state, to_state) + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailsearch", "0006_customise_indexentry"), + ] + + operations = [ + DeleteModelIfExists( + name="EditorsPick", + ), + ]