Skip to content

Commit

Permalink
Revert "Fix migrations (#151)"
Browse files Browse the repository at this point in the history
This reverts commit d35a7fe.
  • Loading branch information
mvantellingen committed May 31, 2017
1 parent 763a67e commit 18838b2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
7 changes: 3 additions & 4 deletions sandbox/sandbox/apps/home/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-31 16:07
# Generated by Django 1.11.1 on 2017-05-31 10:20
from __future__ import unicode_literals

from django.db import migrations, models
Expand All @@ -11,8 +11,7 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('wagtail_personalisation', '0010_auto_20170531_1101'),
('wagtailcore', '0033_remove_golive_expiry_help_text'),
('wagtail_personalisation', '0009_auto_20170531_0428'),
]

operations = [
Expand All @@ -22,7 +21,7 @@ class Migration(migrations.Migration):
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('is_segmented', models.BooleanField(default=False)),
('canonical_page', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='variations', to='home.HomePage')),
('segment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='wagtail_personalisation.Segment')),
('segment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='segments', to='wagtail_personalisation.Segment')),
],
options={
'abstract': False,
Expand Down
59 changes: 59 additions & 0 deletions sandbox/sandbox/apps/home/migrations/0002_create_homepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations


def create_homepage(apps, schema_editor):
# Get models
ContentType = apps.get_model('contenttypes.ContentType')
Page = apps.get_model('wagtailcore.Page')
Site = apps.get_model('wagtailcore.Site')
HomePage = apps.get_model('home.HomePage')

# Delete the default homepage
# If migration is run multiple times, it may have already been deleted
Page.objects.filter(id=2).delete()

# Create content type for homepage model
homepage_content_type, __ = ContentType.objects.get_or_create(
model='homepage', app_label='home')

# Create a new homepage
homepage = HomePage.objects.create(
title="Home",
slug='home',
content_type=homepage_content_type,
path='00010001',
depth=2,
numchild=0,
url_path='/home/',
)

# Create a site with the new homepage set as the root
Site.objects.create(
hostname='localhost', root_page=homepage, is_default_site=True)


def remove_homepage(apps, schema_editor):
# Get models
ContentType = apps.get_model('contenttypes.ContentType')
HomePage = apps.get_model('home.HomePage')

# Delete the default homepage
# Page and Site objects CASCADE
HomePage.objects.filter(slug='home', depth=2).delete()

# Delete content type for homepage model
ContentType.objects.filter(model='homepage', app_label='home').delete()


class Migration(migrations.Migration):

dependencies = [
('home', '0001_initial'),
]

operations = [
migrations.RunPython(create_homepage, remove_homepage),
]
2 changes: 1 addition & 1 deletion sandbox/sandbox/apps/user/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-31 16:07
# Generated by Django 1.11.1 on 2017-05-31 12:22
from __future__ import unicode_literals

import django.contrib.auth.models
Expand Down

0 comments on commit 18838b2

Please sign in to comment.