kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Revise wagtailsearch migrations to avoid keeping editorspick table around
Fixes #1824, as per the outline in https://github.com/wagtail/wagtail/issues/1824#issuecomment-1271840741. Revise the existing migrations so that rather than keeping the wagtailsearch_editorspick table in place and unmanaged for the wagtail.contrib.search_promotions app to potentially rename and adopt, search_promotions creates its own table. This then leaves wagtailsearch free to delete wagtailsearch_editorspick properly in a new migration, to be run on both new and upgraded projects (although this needs to be done inside an existence check, in case the old version of the search_promotions app migrations have already run and renamed the table).pull/9386/head
							rodzic
							
								
									4b0f69fc04
								
							
						
					
					
						commit
						f37768ecaf
					
				| 
						 | 
				
			
			@ -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",),
 | 
			
		||||
            },
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
    ]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
		Ładowanie…
	
		Reference in New Issue