diff --git a/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py b/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py index dadfb353a4..7a29e219c0 100644 --- a/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py +++ b/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py @@ -45,15 +45,15 @@ def initial_data(apps, schema_editor): ) # Create default site - Site.objects.create( + Site.objects.get_or_create( hostname='localhost', root_page_id=homepage.id, is_default_site=True ) # Create auth groups - moderators_group = Group.objects.create(name='Moderators') - editors_group = Group.objects.create(name='Editors') + moderators_group, created = Group.objects.get_or_create(name='Moderators') + editors_group, created = Group.objects.get_or_create(name='Editors') # Create group permissions 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): replaces = [ @@ -306,6 +331,6 @@ class Migration(migrations.Migration): options={'verbose_name': 'Site'}, ), migrations.RunPython( - initial_data, + initial_data, remove_initial_data ), ] diff --git a/wagtail/wagtailcore/migrations/0002_initial_data.py b/wagtail/wagtailcore/migrations/0002_initial_data.py index f3f554873d..d0f74c1dce 100644 --- a/wagtail/wagtailcore/migrations/0002_initial_data.py +++ b/wagtail/wagtailcore/migrations/0002_initial_data.py @@ -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): dependencies = [ @@ -88,5 +113,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(initial_data), + migrations.RunPython(initial_data, remove_initial_data), ]