Commit 2d9708da by Kevin Falcone

Remove uses of using() from migrations

This hardcoded the db_alias fetched from schema_editor and forces django
to try and migrate any second database you use, rather than routing to
the default database.  In testing a build from scratch, these do not
appear needed.

Using using() prevents us from using multiple databases behind edxapp.

Additionally - add back a removed backwards migration from certificates
0003.  I have no idea why this was dropped in the 1.8 upgrade.
parent 6723b896
......@@ -12,9 +12,8 @@ def create_dark_lang_config(apps, schema_editor):
release of testing languages.
"""
DarkLangConfig = apps.get_model("dark_lang", "DarkLangConfig")
db_alias = schema_editor.connection.alias
objects = DarkLangConfig.objects.using(db_alias)
objects = DarkLangConfig.objects
if not objects.exists():
objects.create(enabled=True)
......
......@@ -10,15 +10,13 @@ from django_countries import countries
def create_embargo_countries(apps, schema_editor):
"""Populate the available countries with all 2-character ISO country codes. """
country_model = apps.get_model("embargo", "Country")
db_alias = schema_editor.connection.alias
for country_code, __ in list(countries):
country_model.objects.using(db_alias).get_or_create(country=country_code)
country_model.objects.get_or_create(country=country_code)
def remove_embargo_countries(apps, schema_editor):
"""Clear all available countries. """
country_model = apps.get_model("embargo", "Country")
db_alias = schema_editor.connection.alias
country_model.objects.using(db_alias).all().delete()
country_model.objects.all().delete()
class Migration(migrations.Migration):
......
......@@ -9,8 +9,7 @@ from django.db import migrations, models
def forwards(apps, schema_editor):
"""Ensure that rate limiting is enabled by default. """
RateLimitConfiguration = apps.get_model("util", "RateLimitConfiguration")
db_alias = schema_editor.connection.alias
objects = RateLimitConfiguration.objects.using(db_alias)
objects = RateLimitConfiguration.objects
if not objects.exists():
objects.create(enabled=True)
......
......@@ -33,9 +33,8 @@ def forwards(apps, schema_editor):
}
}
certificate_html_view_configuration_model = apps.get_model("certificates", "CertificateHtmlViewConfiguration")
db_alias = schema_editor.connection.alias
objects = certificate_html_view_configuration_model.objects.using(db_alias)
objects = certificate_html_view_configuration_model.objects
if not objects.exists():
objects.create(
configuration=json.dumps(config),
......@@ -47,9 +46,8 @@ def backwards(apps, schema_editor):
Rolling back to zero-state, so remove all currently-defined configurations
"""
certificate_html_view_configuration_model = apps.get_model("certificates", "CertificateHtmlViewConfiguration")
db_alias = schema_editor.connection.alias
certificate_html_view_configuration_model.objects.using(db_alias).all().delete()
certificate_html_view_configuration_model.objects.all().delete()
class Migration(migrations.Migration):
......
......@@ -10,9 +10,8 @@ from django.core.files import File
def forwards(apps, schema_editor):
"""Add default modes"""
BadgeImageConfiguration = apps.get_model("certificates", "BadgeImageConfiguration")
db_alias = schema_editor.connection.alias
objects = BadgeImageConfiguration.objects.using(db_alias)
objects = BadgeImageConfiguration.objects
if not objects.exists():
for mode in ['honor', 'verified', 'professional']:
conf = objects.create(mode=mode)
......@@ -24,6 +23,9 @@ def forwards(apps, schema_editor):
conf.save()
def backwards(apps, schema_editor):
"""Do nothing, assumptions too dangerous."""
pass
class Migration(migrations.Migration):
......@@ -32,5 +34,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(forwards)
migrations.RunPython(forwards,backwards)
]
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