diff --git a/common/djangoapps/student/migrations/0025_auto_20191101_1846.py b/common/djangoapps/student/migrations/0025_auto_20191101_1846.py new file mode 100644 index 0000000000..1bbfc0d683 --- /dev/null +++ b/common/djangoapps/student/migrations/0025_auto_20191101_1846.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.25 on 2019-11-01 18:46 +from __future__ import unicode_literals + +from django.db import migrations + +from experiments.models import ExperimentData +from openedx.features.course_duration_limits.config import EXPERIMENT_DATA_HOLDBACK_KEY, EXPERIMENT_ID +from student.models import CourseEnrollment, FBEEnrollmentExclusion + + +def populate_fbeenrollmentexclusion(apps, schema_editor): + holdback_entries = ExperimentData.objects.filter( + experiment_id=EXPERIMENT_ID, + key=EXPERIMENT_DATA_HOLDBACK_KEY, + value='True' + ) + for holdback_entry in holdback_entries: + enrollments = [FBEEnrollmentExclusion(enrollment=enrollment) + for enrollment in CourseEnrollment.objects.filter(user=holdback_entry.user)] + if enrollments: + FBEEnrollmentExclusion.objects.bulk_create(enrollments) + + +class Migration(migrations.Migration): + + dependencies = [ + ('student', '0024_fbeenrollmentexclusion'), + ] + + operations = [ + migrations.RunPython(populate_fbeenrollmentexclusion, reverse_code=migrations.RunPython.noop), + ]