0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Make wagtailcore 0002 reversible

This commit is contained in:
Benjamin Bach 2015-12-28 02:46:14 +01:00 committed by Karl Hobley
parent bb75190ec6
commit f88c169665
2 changed files with 55 additions and 5 deletions

View File

@ -45,15 +45,15 @@ def initial_data(apps, schema_editor):
) )
# Create default site # Create default site
Site.objects.create( Site.objects.get_or_create(
hostname='localhost', hostname='localhost',
root_page_id=homepage.id, root_page_id=homepage.id,
is_default_site=True is_default_site=True
) )
# Create auth groups # Create auth groups
moderators_group = Group.objects.create(name='Moderators') moderators_group, created = Group.objects.get_or_create(name='Moderators')
editors_group = Group.objects.create(name='Editors') editors_group, created = Group.objects.get_or_create(name='Editors')
# Create group permissions # Create group permissions
GroupPagePermission.objects.create( GroupPagePermission.objects.create(
@ -91,6 +91,31 @@ def initial_data(apps, schema_editor):
) )
def remove_initial_data(apps, schema_editor):
"""This function does nothing. The below code is commented out together
with an explanation of why we don't need to bother reversing any of the
initial data"""
pass
# This does not need to be deleted, Django takes care of it.
# page_content_type = ContentType.objects.get(
# model='page',
# app_label='wagtailcore',
# )
# Page objects: Do nothing, the table will be deleted when reversing 0001
# Do not reverse Site creation since other models might depend on it
# Remove auth groups -- is this safe? External objects might depend
# on these groups... seems unsafe.
# Group.objects.filter(
# name__in=('Moderators', 'Editors')
# ).delete()
#
# Likewise, we're leaving all GroupPagePermission unchanged as users may
# have been assigned such permissions and its harmless to leave them.
class Migration(migrations.Migration): class Migration(migrations.Migration):
replaces = [ replaces = [
@ -306,6 +331,6 @@ class Migration(migrations.Migration):
options={'verbose_name': 'Site'}, options={'verbose_name': 'Site'},
), ),
migrations.RunPython( migrations.RunPython(
initial_data, initial_data, remove_initial_data
), ),
] ]

View File

@ -81,6 +81,31 @@ def initial_data(apps, schema_editor):
) )
def remove_initial_data(apps, schema_editor):
"""This function does nothing. The below code is commented out together
with an explanation of why we don't need to bother reversing any of the
initial data"""
pass
# This does not need to be deleted, Django takes care of it.
# page_content_type = ContentType.objects.get(
# model='page',
# app_label='wagtailcore',
# )
# Page objects: Do nothing, the table will be deleted when reversing 0001
# Do not reverse Site creation since other models might depend on it
# Remove auth groups -- is this safe? External objects might depend
# on these groups... seems unsafe.
# Group.objects.filter(
# name__in=('Moderators', 'Editors')
# ).delete()
#
# Likewise, we're leaving all GroupPagePermission unchanged as users may
# have been assigned such permissions and its harmless to leave them.
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@ -88,5 +113,5 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(initial_data), migrations.RunPython(initial_data, remove_initial_data),
] ]