From 509390590bf7f3e9571d68b39cafdf932dd47baf Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sun, 30 Dec 2018 10:42:05 +0100 Subject: [PATCH 1/2] Split migration 0056 We can not change structure and migrate data at the same time on some db engines. So this commit splits the operation. --- ...radiusoption.py => 0056_1_radiusoption.py} | 27 --------------- preferences/migrations/0056_2_radiusoption.py | 33 +++++++++++++++++++ preferences/migrations/0056_3_radiusoption.py | 31 +++++++++++++++++ .../migrations/0057_auto_20181204_0757.py | 2 +- 4 files changed, 65 insertions(+), 28 deletions(-) rename preferences/migrations/{0056_radiusoption.py => 0056_1_radiusoption.py} (84%) create mode 100644 preferences/migrations/0056_2_radiusoption.py create mode 100644 preferences/migrations/0056_3_radiusoption.py diff --git a/preferences/migrations/0056_radiusoption.py b/preferences/migrations/0056_1_radiusoption.py similarity index 84% rename from preferences/migrations/0056_radiusoption.py rename to preferences/migrations/0056_1_radiusoption.py index e329f598..8a7cb45c 100644 --- a/preferences/migrations/0056_radiusoption.py +++ b/preferences/migrations/0056_1_radiusoption.py @@ -7,19 +7,6 @@ import django.db.models.deletion import re2o.mixins -def create_radius_policy(apps, schema_editor): - OptionalTopologie = apps.get_model('preferences', 'OptionalTopologie') - RadiusOption = apps.get_model('preferences', 'RadiusOption') - - option,_ = OptionalTopologie.objects.get_or_create() - - radius_option = RadiusOption() - radius_option.radius_general_policy = option.radius_general_policy - radius_option.vlan_decision_ok = option.vlan_decision_ok - - radius_option.save() - - class Migration(migrations.Migration): dependencies = [ @@ -94,18 +81,4 @@ class Migration(migrations.Migration): name='vlan_decision_ok', field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vlan_ok_option', to='machines.Vlan'), ), - - migrations.RunPython(create_radius_policy), - migrations.RemoveField( - model_name='optionaltopologie', - name='radius_general_policy', - ), - migrations.RemoveField( - model_name='optionaltopologie', - name='vlan_decision_nok', - ), - migrations.RemoveField( - model_name='optionaltopologie', - name='vlan_decision_ok', - ), ] diff --git a/preferences/migrations/0056_2_radiusoption.py b/preferences/migrations/0056_2_radiusoption.py new file mode 100644 index 00000000..69d81055 --- /dev/null +++ b/preferences/migrations/0056_2_radiusoption.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-10-13 14:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import re2o.mixins + + +def create_radius_policy(apps, schema_editor): + OptionalTopologie = apps.get_model('preferences', 'OptionalTopologie') + RadiusOption = apps.get_model('preferences', 'RadiusOption') + + option,_ = OptionalTopologie.objects.get_or_create() + + radius_option = RadiusOption() + radius_option.radius_general_policy = option.radius_general_policy + radius_option.vlan_decision_ok = option.vlan_decision_ok + + radius_option.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0095_auto_20180919_2225'), + ('preferences', '0055_generaloption_main_site_url'), + ('preferences', '0056_1_radiusoption'), + ] + + operations = [ + migrations.RunPython(create_radius_policy), + ] diff --git a/preferences/migrations/0056_3_radiusoption.py b/preferences/migrations/0056_3_radiusoption.py new file mode 100644 index 00000000..f3e5f98c --- /dev/null +++ b/preferences/migrations/0056_3_radiusoption.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-10-13 14:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import re2o.mixins + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0095_auto_20180919_2225'), + ('preferences', '0055_generaloption_main_site_url'), + ('preferences', '0056_2_radiusoption'), + ] + + operations = [ + migrations.RemoveField( + model_name='optionaltopologie', + name='radius_general_policy', + ), + migrations.RemoveField( + model_name='optionaltopologie', + name='vlan_decision_nok', + ), + migrations.RemoveField( + model_name='optionaltopologie', + name='vlan_decision_ok', + ), + ] diff --git a/preferences/migrations/0057_auto_20181204_0757.py b/preferences/migrations/0057_auto_20181204_0757.py index ba4e1a6f..8d93fff9 100644 --- a/preferences/migrations/0057_auto_20181204_0757.py +++ b/preferences/migrations/0057_auto_20181204_0757.py @@ -8,7 +8,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('preferences', '0056_radiusoption'), + ('preferences', '0056_3_radiusoption'), ] operations = [ From 7318ee47583bb1cf7d0e68e209f2fcee72e4d267 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 30 Dec 2018 14:56:25 +0100 Subject: [PATCH 2/2] Rename migration + revert function radiusoption --- preferences/migrations/0056_2_radiusoption.py | 5 ++++- .../{0057_auto_20181204_0757.py => 0056_4_radiusoption.py} | 0 2 files changed, 4 insertions(+), 1 deletion(-) rename preferences/migrations/{0057_auto_20181204_0757.py => 0056_4_radiusoption.py} (100%) diff --git a/preferences/migrations/0056_2_radiusoption.py b/preferences/migrations/0056_2_radiusoption.py index 69d81055..1a8ecccd 100644 --- a/preferences/migrations/0056_2_radiusoption.py +++ b/preferences/migrations/0056_2_radiusoption.py @@ -19,6 +19,9 @@ def create_radius_policy(apps, schema_editor): radius_option.save() +def revert_radius(apps, schema_editor): + pass + class Migration(migrations.Migration): @@ -29,5 +32,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(create_radius_policy), + migrations.RunPython(create_radius_policy, revert_radius), ] diff --git a/preferences/migrations/0057_auto_20181204_0757.py b/preferences/migrations/0056_4_radiusoption.py similarity index 100% rename from preferences/migrations/0057_auto_20181204_0757.py rename to preferences/migrations/0056_4_radiusoption.py