From 4940cda1806aa13591485b996264ddc887202d35 Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Thu, 27 Feb 2020 16:26:47 -0500 Subject: Improve Data Migration Improved migration files so that they preserve data Change-Id: I53283fd3fd207ed3f9773beea7b1ce2062b5bd9f Signed-off-by: Parker Berberian --- src/api/migrations/0011_auto_20200218_1536.py | 25 --------------------- src/api/migrations/0012_manual_20200218_1536.py | 22 +++++++++++++++++++ src/api/migrations/0012_manual_20200220.py | 18 --------------- src/api/migrations/0013_manual_20200218_1536.py | 29 +++++++++++++++++++++++++ src/api/migrations/0014_manual_20200220.py | 18 +++++++++++++++ 5 files changed, 69 insertions(+), 43 deletions(-) create mode 100644 src/api/migrations/0012_manual_20200218_1536.py delete mode 100644 src/api/migrations/0012_manual_20200220.py create mode 100644 src/api/migrations/0013_manual_20200218_1536.py create mode 100644 src/api/migrations/0014_manual_20200220.py (limited to 'src/api') diff --git a/src/api/migrations/0011_auto_20200218_1536.py b/src/api/migrations/0011_auto_20200218_1536.py index a399495..0fd7029 100644 --- a/src/api/migrations/0011_auto_20200218_1536.py +++ b/src/api/migrations/0011_auto_20200218_1536.py @@ -3,14 +3,6 @@ from django.db import migrations, models -def set_resource_id(apps, schema_editor): - for cls in ["HardwareConfig", "NetworkConfig", "SnapshotConfig"]: - model = apps.get_model('api', cls) - for m in model.objects.all(): - m.resource_id = m.host.labid - m.save() - - class Migration(migrations.Migration): dependencies = [ @@ -34,21 +26,4 @@ class Migration(migrations.Migration): name='resource_id', field=models.CharField(default='default_id', max_length=200), ), - migrations.RunPython(set_resource_id), - migrations.RemoveField( - model_name='hosthardwarerelation', - name='host', - ), - migrations.RemoveField( - model_name='hostnetworkrelation', - name='host', - ), - migrations.RemoveField( - model_name='snapshotconfig', - name='host', - ), - migrations.RemoveField( - model_name='opnfvapiconfig', - name='roles', - ), ] diff --git a/src/api/migrations/0012_manual_20200218_1536.py b/src/api/migrations/0012_manual_20200218_1536.py new file mode 100644 index 0000000..55befbd --- /dev/null +++ b/src/api/migrations/0012_manual_20200218_1536.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2 on 2020-02-18 15:36 + +from django.db import migrations + + +def set_resource_id(apps, schema_editor): + for cls in ["HostHardwareRelation", "HostNetworkRelation", "SnapshotConfig"]: + model = apps.get_model('api', cls) + for m in model.objects.all(): + m.resource_id = m.host.labid + m.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0011_auto_20200218_1536'), + ] + + operations = [ + migrations.RunPython(set_resource_id), + ] diff --git a/src/api/migrations/0012_manual_20200220.py b/src/api/migrations/0012_manual_20200220.py deleted file mode 100644 index 40f7e79..0000000 --- a/src/api/migrations/0012_manual_20200220.py +++ /dev/null @@ -1,18 +0,0 @@ - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0011_auto_20200218_1536'), - ('resource_inventory', '0013_auto_20200218_1536') - ] - - operations = [ - migrations.AddField( - model_name='opnfvapiconfig', - name='roles', - field=models.ManyToManyField(to='resource_inventory.ResourceOPNFVConfig'), - ), - ] diff --git a/src/api/migrations/0013_manual_20200218_1536.py b/src/api/migrations/0013_manual_20200218_1536.py new file mode 100644 index 0000000..0b76e84 --- /dev/null +++ b/src/api/migrations/0013_manual_20200218_1536.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2 on 2020-02-18 15:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0012_manual_20200218_1536'), + ] + + operations = [ + migrations.RemoveField( + model_name='hosthardwarerelation', + name='host', + ), + migrations.RemoveField( + model_name='hostnetworkrelation', + name='host', + ), + migrations.RemoveField( + model_name='snapshotconfig', + name='host', + ), + migrations.RemoveField( + model_name='opnfvapiconfig', + name='roles', + ), + ] diff --git a/src/api/migrations/0014_manual_20200220.py b/src/api/migrations/0014_manual_20200220.py new file mode 100644 index 0000000..2e2cd58 --- /dev/null +++ b/src/api/migrations/0014_manual_20200220.py @@ -0,0 +1,18 @@ + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0013_manual_20200218_1536'), + ('resource_inventory', '0013_auto_20200218_1536') + ] + + operations = [ + migrations.AddField( + model_name='opnfvapiconfig', + name='roles', + field=models.ManyToManyField(to='resource_inventory.ResourceOPNFVConfig'), + ), + ] -- cgit 1.2.3-korg