layerindex-web/rrs/migrations/0015_rmh_layerbranch_populate.py
Paul Eggleton 7606664eeb rrs: link maintenance/upstream history to layerbranch
RecipeUpstreamHistory was not linked to the layer it was produced from,
which meant that it wasn't easy to query for a different maintenance
plan (i.e. a different layer) and thus the maintenance plan selection
on the recipe list didn't really work. Add a link field, populate it in
a migration and then make it required.

We had added a link earlier from RecipeMaintainerHistory to LayerBranch
but it was optional; for the same reasons we now populate it and make it
required.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
2018-05-04 23:57:53 +12:00

30 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import settings
def populate_rmh_layerbranch(apps, schema_editor):
RecipeMaintainerHistory = apps.get_model('rrs', 'RecipeMaintainerHistory')
LayerBranch = apps.get_model('layerindex', 'LayerBranch')
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)
for row in RecipeMaintainerHistory.objects.all():
row.layerbranch = core_layerbranch
row.save()
class Migration(migrations.Migration):
dependencies = [
('rrs', '0014_reup_layerbranch_nonnull'),
]
operations = [
migrations.RunPython(populate_rmh_layerbranch, reverse_code=migrations.RunPython.noop),
]