Commit 7e8dc6b2 by Ahsan Ulhaq Committed by Ned Batchelder

Cherry-pick the email uniqueness constraint onto Ficus

Added unique constraint on email
ECOM-7085

(cherry picked from commit d141eb15)

No-op a migration that needs to be more clever

(cherry picked from commit 1e6a74e7)

model_name can be non-None, and model is still None

(cherry picked from commit 52ca02fd)

An idempotent migration to add an email uniqueness constraint

(cherry picked from commit 169414b7)

Make this no-op migration be a true no-op.

(cherry picked from commit 04557bbf)

A new django app for unicorn migrations

(cherry picked from commit 98b250b6)
parent 3988a349
...@@ -956,6 +956,9 @@ INSTALLED_APPS = ( ...@@ -956,6 +956,9 @@ INSTALLED_APPS = (
# management of user-triggered async tasks (course import/export, etc.) # management of user-triggered async tasks (course import/export, etc.)
'user_tasks', 'user_tasks',
# Unusual migrations
'database_fixups',
) )
......
"""
This app exists solely to host unusual database migrations.
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
# We used to have a uniqueness constraint on auth_user.email:
# https://github.com/edx/edx-platform/commit/c52727b0e0fb241d8211900975d3b69fe5a1bd57
#
# That constraint was lost in the upgrade from Django 1.4->1.8. This migration
# adds it back. But because it might already exist in databases created
# long-enough ago, we have to do it idempotently. So we check for the
# existence of the constraint before creating it.
def add_email_uniqueness_constraint(apps, schema_editor):
# Do we already have an email uniqueness constraint?
cursor = schema_editor.connection.cursor()
constraints = schema_editor.connection.introspection.get_constraints(cursor, "auth_user")
email_constraint = constraints.get("email", {})
if email_constraint.get("columns") == ["email"] and email_constraint.get("unique") == True:
# We already have the constraint, we're done.
return
# We don't have the constraint, make it.
schema_editor.execute("create unique index email on auth_user (email)")
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.RunPython(add_email_uniqueness_constraint)
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('student', '0009_auto_20170111_0422'),
]
# This migration was to add a constraint that we lost in the Django
# 1.4->1.8 upgrade. But since the constraint used to be created, production
# would already have the constraint even before running the migration, and
# running the migration would fail. We needed to make the migration
# idempotent. Instead of reverting this migration while we did that, we
# edited it to be a SQL no-op, so that people who had already applied it
# wouldn't end up with a ghost migration.
# It had been:
#
# migrations.RunSQL(
# "create unique index email on auth_user (email);",
# "drop index email on auth_user;"
# )
operations = [
# Nothing to do.
]
...@@ -2154,6 +2154,9 @@ INSTALLED_APPS = ( ...@@ -2154,6 +2154,9 @@ INSTALLED_APPS = (
# additional release utilities to ease automation # additional release utilities to ease automation
'release_util', 'release_util',
# Unusual migrations
'database_fixups',
) )
# Migrations which are not in the standard module "migrations" # Migrations which are not in the standard module "migrations"
......
...@@ -45,13 +45,15 @@ class StudentModuleHistoryExtendedRouter(object): ...@@ -45,13 +45,15 @@ class StudentModuleHistoryExtendedRouter(object):
return False return False
return None return None
def allow_migrate(self, db, model): # pylint: disable=unused-argument def allow_migrate(self, db, app_label, model_name=None, **hints): # pylint: disable=unused-argument
""" """
Only sync StudentModuleHistoryExtended to StudentModuleHistoryExtendedRouter.DATABASE_Name Only sync StudentModuleHistoryExtended to StudentModuleHistoryExtendedRouter.DATABASE_Name
""" """
if self._is_csmh(model): if model_name is not None:
return db == self.DATABASE_NAME model = hints.get('model')
elif db == self.DATABASE_NAME: if model is not None and self._is_csmh(model):
return db == self.DATABASE_NAME
if db == self.DATABASE_NAME:
return False return False
return None return None
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