Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
f9e9b72d
Commit
f9e9b72d
authored
5 years ago
by
Joseph Mulloy
Browse files
Options
Downloads
Patches
Plain Diff
Add CSM primary key to bigint migration
parent
5012ed6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py
+38
-0
38 additions, 0 deletions
lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py
lms/djangoapps/courseware/models.py
+3
-0
3 additions, 0 deletions
lms/djangoapps/courseware/models.py
with
41 additions
and
0 deletions
lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py
0 → 100644
+
38
−
0
View file @
f9e9b72d
# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-08-28 15:50
from
__future__
import
unicode_literals
import
courseware.fields
from
django.db
import
migrations
from
django.db.migrations
import
AlterField
class
CsmBigInt
(
AlterField
):
'''
Subclass AlterField migration class to split SQL between two different databases
We can
'
t use the normal AlterField migration operation because Django generate and routes migrations at the model
level and the coursewarehistoryextended_studentmodulehistoryextended table is in a different database
'''
def
database_forwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
to_model
=
to_state
.
apps
.
get_model
(
app_label
,
self
.
model_name
)
if
schema_editor
.
connection
.
alias
==
'
student_module_history
'
:
schema_editor
.
execute
(
"
ALTER TABLE `coursewarehistoryextended_studentmodulehistoryextended` MODIFY `student_module_id` bigint UNSIGNED NOT NULL;
"
)
elif
self
.
allow_migrate_model
(
schema_editor
.
connection
.
alias
,
to_model
):
schema_editor
.
execute
(
"
ALTER TABLE `courseware_studentmodule` MODIFY `id` bigint UNSIGNED AUTO_INCREMENT NOT NULL;
"
)
def
database_backwards
(
self
,
app_label
,
schema_editor
,
from_state
,
to_state
):
# Make backwards migration a no-op, app will still work if column is wider than expected
pass
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
courseware
'
,
'
0010_auto_20190709_1559
'
),
]
operations
=
[
CsmBigInt
(
model_name
=
'
studentmodule
'
,
name
=
'
id
'
,
field
=
courseware
.
fields
.
UnsignedBigIntAutoField
(
primary_key
=
True
,
serialize
=
False
),
)
]
This diff is collapsed.
Click to expand it.
lms/djangoapps/courseware/models.py
+
3
−
0
View file @
f9e9b72d
...
...
@@ -26,6 +26,7 @@ from django.db.models.signals import post_save
from
django.utils.translation
import
ugettext_lazy
as
_
from
model_utils.models
import
TimeStampedModel
from
opaque_keys.edx.django.models
import
BlockTypeKeyField
,
CourseKeyField
,
UsageKeyField
from
courseware.fields
import
UnsignedBigIntAutoField
from
six
import
text_type
from
six.moves
import
range
...
...
@@ -95,6 +96,8 @@ class StudentModule(models.Model):
(
'
sequential
'
,
'
Subsection
'
),
(
'
library_content
'
,
'
Library Content
'
))
id
=
UnsignedBigIntAutoField
(
primary_key
=
True
)
# pylint: disable=invalid-name
## These three are the key for the object
module_type
=
models
.
CharField
(
max_length
=
32
,
choices
=
MODULE_TYPES
,
default
=
'
problem
'
,
db_index
=
True
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment