aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2018-02-28 10:03:27 +1300
committerPaul Eggleton <paul.eggleton@linux.intel.com>2018-05-04 23:57:52 +1200
commit24960bb7be87880deda705348106d39ab6f63ea3 (patch)
tree84b57d9280273028332d4b08201e6dca58790cc0
parent1f49943aee6164ffd734fa1e46d38d2b3d635e31 (diff)
downloadopenembedded-core-contrib-24960bb7be87880deda705348106d39ab6f63ea3.tar.gz
rrs: add Release link to MaintenancePlan
If any Releases exist then we create a default MaintenancePlan and then link all Releases to it - this needs to be done in multiple upgrade steps since the field needs to be non-null. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--rrs/migrations/0003_release_plan.py19
-rw-r--r--rrs/migrations/0004_maint_plan_default.py39
-rw-r--r--rrs/migrations/0005_release_plan_nonnull.py19
-rw-r--r--rrs/models.py1
4 files changed, 78 insertions, 0 deletions
diff --git a/rrs/migrations/0003_release_plan.py b/rrs/migrations/0003_release_plan.py
new file mode 100644
index 0000000000..934ac4b242
--- /dev/null
+++ b/rrs/migrations/0003_release_plan.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('rrs', '0002_maintenanceplan'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='release',
+ name='plan',
+ field=models.ForeignKey(null=True, to='rrs.MaintenancePlan'),
+ ),
+ ]
diff --git a/rrs/migrations/0004_maint_plan_default.py b/rrs/migrations/0004_maint_plan_default.py
new file mode 100644
index 0000000000..1d192d04f9
--- /dev/null
+++ b/rrs/migrations/0004_maint_plan_default.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import settings
+
+
+def populate_plan(apps, schema_editor):
+ Release = apps.get_model('rrs', 'Release')
+ MaintenancePlan = apps.get_model('rrs', 'MaintenancePlan')
+ LayerBranch = apps.get_model('layerindex', 'LayerBranch')
+ MaintenancePlanLayerBranch = apps.get_model('rrs', 'MaintenancePlanLayerBranch')
+
+ if Release.objects.all().exists():
+ if not settings.CORE_LAYER_NAME:
+ raise Exception('Please set CORE_LAYER_NAME in settings.py')
+ core_layerbranch = LayerBranch.objects.filter(layer__name=settings.CORE_LAYER_NAME).first()
+ if not core_layerbranch:
+ raise Exception('Unable to find core layer "%s" specified in CORE_LAYER_NAME in settings.py - please set up the layerindex application first' % settings.CORE_LAYER_NAME)
+ maintplan = MaintenancePlan()
+ maintplan.name = 'Default'
+ maintplan.description = 'Created upon database upgrade'
+ maintplan.save()
+ for row in Release.objects.all():
+ row.plan = maintplan
+ row.save()
+ maintplanlayerbranch = MaintenancePlanLayerBranch(plan=maintplan, layerbranch=core_layerbranch)
+ maintplanlayerbranch.save();
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('rrs', '0003_release_plan'),
+ ]
+
+ operations = [
+ migrations.RunPython(populate_plan, reverse_code=migrations.RunPython.noop),
+ ]
diff --git a/rrs/migrations/0005_release_plan_nonnull.py b/rrs/migrations/0005_release_plan_nonnull.py
new file mode 100644
index 0000000000..c797ae5948
--- /dev/null
+++ b/rrs/migrations/0005_release_plan_nonnull.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('rrs', '0004_maint_plan_default'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='release',
+ name='plan',
+ field=models.ForeignKey(to='rrs.MaintenancePlan'),
+ ),
+ ]
diff --git a/rrs/models.py b/rrs/models.py
index ebce4c3b53..2a10f253a1 100644
--- a/rrs/models.py
+++ b/rrs/models.py
@@ -31,6 +31,7 @@ class MaintenancePlanLayerBranch(models.Model):
verbose_name_plural = "Maintenance plan layer branches"
class Release(models.Model):
+ plan = models.ForeignKey(MaintenancePlan)
name = models.CharField(max_length=100, unique=True)
start_date = models.DateField(db_index=True)
end_date = models.DateField(db_index=True)