Commit aa09c26d by Ned Batchelder

Merge pull request #56 from edx/ned/convert-data-migration

Convert the data migration to a Django migration
parents 2e0bfb88 901feb3e
......@@ -6,28 +6,6 @@ import django.core.validators
import edxval.models
def forwards_default_profiles(apps, schema_editor):
""" Add default profiles """
Profile = apps.get_model("edxval", "Profile")
db_alias = schema_editor.connection.alias
Profile.objects.using(db_alias).bulk_create([
Profile(profile_name="desktop_mp4"),
Profile(profile_name="desktop_webm"),
Profile(profile_name="mobile_high"),
Profile(profile_name="mobile_low"),
Profile(profile_name="youtube"),
])
def reverse_default_profiles(apps, schema_editor):
""" Remove default profiles """
Profile = apps.get_model("edxval", "Profile")
db_alias = schema_editor.connection.alias
Profile.objects.using(db_alias).filter(
profile_name__in=["desktop_mp4", "desktop_webm", "mobile_high", "mobile_low", "youtube"]
).delete()
class Migration(migrations.Migration):
dependencies = [
......@@ -106,5 +84,4 @@ class Migration(migrations.Migration):
name='coursevideo',
unique_together=set([('course_id', 'video')]),
),
migrations.RunPython(forwards_default_profiles, reverse_default_profiles, atomic=False),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
DEFAULT_PROFILES = [
"desktop_mp4",
"desktop_webm",
"mobile_high",
"mobile_low",
"youtube",
]
def create_default_profiles(apps, schema_editor):
""" Add default profiles """
Profile = apps.get_model("edxval", "Profile")
db_alias = schema_editor.connection.alias
for profile in DEFAULT_PROFILES:
Profile.objects.using(db_alias).get_or_create(profile_name=profile)
def delete_default_profiles(apps, schema_editor):
""" Remove default profiles """
Profile = apps.get_model("edxval", "Profile")
db_alias = schema_editor.connection.alias
Profile.objects.using(db_alias).filter(profile_name__in=DEFAULT_PROFILES).delete()
class Migration(migrations.Migration):
dependencies = [
('edxval', '0001_initial'),
]
operations = [
migrations.RunPython(create_default_profiles, delete_default_profiles),
]
......@@ -2,7 +2,9 @@
from setuptools import setup
PACKAGES = [
'edxval'
'edxval',
'edxval.migrations',
'edxval.tests',
]
def is_requirement(line):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment