Merging two wagtail page types into one
Let's say we end up with two page types ContentPage
and Folder
that do the same job and we want to consolidate them into one.
Basically we want to merge Folder
into ContentPage
.
I came up with next solution but want to be sure that I am not missing anything.
- migration:
class Migration(migrations.Migration):
dependencies = [
...
]
operations = [
# copy all `folder` specific fields into `contentpage` table
migrations.RunSQL(
"""
INSERT INTO app_contentpage (
page_ptr_id,
...,
body,
...
) SELECT
...,
body,
...
FROM app_folderpage;
"""
),
# update all tables that have references to `django_content_type` table
# folder.content_type_id = 12
# contentpage.content_type_id = 11
migrations.RunSQL(
"""UPDATE wagtailcore_page SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_modellogentry SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_pagelogentry SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_revision SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_taskstate SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_workflowstate SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailsearch_indexentry SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_workflowcontenttype SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL(
"""UPDATE wagtailcore_task SET content_type_id = 11 WHERE content_type_id = 12;"""
),
migrations.RunSQL("""DELETE FROM app_folderpage;"""),
]
run
python manage.py rebuild_references_index
. Also it might be possible to updatewagtailcore_referenceindex
with SQL but I have feeling that runningrebuild_references_index
is more reliableremove
Folder
model from code and runpython manage.py makemigrations
manually clean up (or create migration) 'auth_permission' and
django_admin_log
where content_type_id is equalfolder.content_type_id
remove
app_folder*
records fromdjango_content_type
I would appreciate any thoughts and comments.