Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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-ora2
Commits
14bc13f3
Commit
14bc13f3
authored
Jul 07, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #475 from edx/will/update-migration
Update migration to add criterion_id to AssessmentPart
parents
c19de519
99983049
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
openassessment/assessment/migrations/0018_auto__add_field_assessmentpart_criterion.py
+27
-4
No files found.
openassessment/assessment/migrations/0018_auto__add_field_assessmentpart_criterion.py
View file @
14bc13f3
# -*- coding: utf-8 -*-
import
datetime
from
contextlib
import
contextmanager
from
south.db
import
db
from
south.v2
import
SchemaMigration
from
django.db
import
models
class
Migration
(
SchemaMigration
):
@contextmanager
def
lock_table
(
self
,
table_name
):
""" Context manager for locking a table (MySQL only) """
# Lock tables only under MySQL (it isn't supported for SQLLite)
is_mysql
=
(
db
.
backend_name
==
'mysql'
)
# Before the block executes, lock the specified table
if
is_mysql
:
db
.
execute
(
"LOCK TABLE {table} WRITE"
.
format
(
table
=
table_name
))
# Execute the block
yield
# Add a deferred statement to unlock tables
# This will ensure that tables stay locked until
# all deferred SQL executes
# (for example, creating foreign key constraints and adding indices)
if
is_mysql
:
db
.
add_deferred_sql
(
"UNLOCK TABLES"
)
def
forwards
(
self
,
orm
):
# Adding field 'AssessmentPart.criterion'
# We need to lock the table to avoid a potential deadlock with the application queries.
# We need to provide a default value of NULL so that the INSERT queries don't
# raise an exception when they don't specify the new field.
with
self
.
lock_table
(
'assessment_assessmentpart'
):
db
.
add_column
(
'assessment_assessmentpart'
,
'criterion'
,
self
.
gf
(
'django.db.models.fields.related.ForeignKey'
)(
related_name
=
'+'
,
null
=
Tru
e
,
to
=
orm
[
'assessment.Criterion'
]),
self
.
gf
(
'django.db.models.fields.related.ForeignKey'
)(
related_name
=
'+'
,
null
=
True
,
default
=
Non
e
,
to
=
orm
[
'assessment.Criterion'
]),
keep_default
=
False
)
def
backwards
(
self
,
orm
):
# Deleting field 'AssessmentPart.criterion'
with
self
.
lock_table
(
'assessment_assessmentpart'
):
db
.
delete_column
(
'assessment_assessmentpart'
,
'criterion_id'
)
...
...
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