Commit bcf789bd by Ned Batchelder

Merge pull request #10590 from edx/ned/dj18-fixed-data-migrations

More-correct data migrations
parents 8bac42a1 e7fcc743
......@@ -11,11 +11,12 @@ def create_dark_lang_config(apps, schema_editor):
Enable DarkLang by default when it is installed, to prevent accidental
release of testing languages.
"""
dark_lang_model = apps.get_model("dark_lang", "DarkLangConfig")
DarkLangConfig = apps.get_model("dark_lang", "DarkLangConfig")
db_alias = schema_editor.connection.alias
if not dark_lang_model.objects.using(db_alias).exists():
dark_lang_model.objects.using(db_alias).create(enabled=True)
objects = DarkLangConfig.objects.using(db_alias)
if not objects.exists():
objects.create(enabled=True)
def remove_dark_lang_config(apps, schema_editor):
"""Write your backwards methods here."""
......
......@@ -8,9 +8,12 @@ from django.db import migrations, models
def forwards(apps, schema_editor):
"""Ensure that rate limiting is enabled by default. """
rate_limit_configuration_model = apps.get_model("util", "RateLimitConfiguration")
RateLimitConfiguration = apps.get_model("util", "RateLimitConfiguration")
db_alias = schema_editor.connection.alias
rate_limit_configuration_model.objects.using(db_alias).get_or_create(enabled=True)
objects = RateLimitConfiguration.objects.using(db_alias)
if not objects.exists():
objects.create(enabled=True)
class Migration(migrations.Migration):
......
......@@ -9,11 +9,13 @@ from django.core.files import File
def forwards(apps, schema_editor):
"""Add default modes"""
badge_image_configuration_model = apps.get_model("certificates", "BadgeImageConfiguration")
BadgeImageConfiguration = apps.get_model("certificates", "BadgeImageConfiguration")
db_alias = schema_editor.connection.alias
for mode in ['honor', 'verified', 'professional']:
conf, created = badge_image_configuration_model.objects.get_or_create(mode=mode)
if created:
objects = BadgeImageConfiguration.objects.using(db_alias)
if not objects.exists():
for mode in ['honor', 'verified', 'professional']:
conf = objects.create(mode=mode)
file_name = '{0}{1}'.format(mode, '.png')
conf.icon.save(
'badges/{}'.format(file_name),
......
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