Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
45fb2269
Commit
45fb2269
authored
Feb 15, 2017
by
Ned Batchelder
Committed by
GitHub
Feb 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14526 from edx/nedbat/ficus-email-constraint
Cherry-pick the email uniqueness constraint onto Ficus
parents
3988a349
7e8dc6b2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
79 additions
and
4 deletions
+79
-4
cms/envs/common.py
+3
-0
common/djangoapps/database_fixups/__init__.py
+3
-0
common/djangoapps/database_fixups/migrations/0001_initial.py
+34
-0
common/djangoapps/database_fixups/migrations/__init__.py
+0
-0
common/djangoapps/student/migrations/0010_auto_20170207_0458.py
+30
-0
lms/envs/common.py
+3
-0
openedx/core/lib/django_courseware_routers.py
+6
-4
No files found.
cms/envs/common.py
View file @
45fb2269
...
@@ -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'
,
)
)
...
...
common/djangoapps/database_fixups/__init__.py
0 → 100644
View file @
45fb2269
"""
This app exists solely to host unusual database migrations.
"""
common/djangoapps/database_fixups/migrations/0001_initial.py
0 → 100644
View file @
45fb2269
# -*- 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
)
]
common/djangoapps/database_fixups/migrations/__init__.py
0 → 100644
View file @
45fb2269
common/djangoapps/student/migrations/0010_auto_20170207_0458.py
0 → 100644
View file @
45fb2269
# -*- 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.
]
lms/envs/common.py
View file @
45fb2269
...
@@ -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"
...
...
openedx/core/lib/django_courseware_routers.py
View file @
45fb2269
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment