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.
This commit is contained in:
Kevin Falcone
2016-02-01 16:49:48 -05:00
parent 6723b89649
commit 2d9708da03
5 changed files with 11 additions and 15 deletions

View File

@@ -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)

View File

@@ -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):

View File

@@ -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)