Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
OpenEdx
problem-builder
Commits
df221117
Commit
df221117
authored
Sep 21, 2017
by
Cliff Dyer
Committed by
GitHub
Sep 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migration to remove deprecated course_id from db. (#168)
Also remove outdated mgmt command. Depends on #166. OC-3033
parent
b1cb2ac8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
71 deletions
+24
-71
problem_builder/management/commands/problem_builder_migrate_keys.py
+0
-70
problem_builder/migrations/0006_remove_deprecated_course_id.py
+23
-0
setup.py
+1
-1
No files found.
problem_builder/management/commands/problem_builder_migrate_keys.py
deleted
100644 → 0
View file @
b1cb2ac8
"""
Command to copy content of Answer.course_id to Answer.course_key.
"""
import
time
from
django.core.management.base
import
BaseCommand
from
django.db.models
import
F
,
Q
from
problem_builder.models
import
Answer
class
Command
(
BaseCommand
):
"""
Copy content of the deprecated Answer.course_id column into
Answer.course_key in batches. The batch size and sleep time between
batches are configurable.
"""
help
=
'Copy content of the deprecated Answer.course_id column to Answer.course_key in batches'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--batch-size'
,
help
=
'The size of each batch of records to copy (default: 5000).'
,
type
=
int
,
default
=
5000
,
)
parser
.
add_argument
(
'--offset'
,
help
=
'The lowest primary key to copy (default: 0)'
,
type
=
int
,
default
=
0
,
)
parser
.
add_argument
(
'--sleep'
,
help
=
'Number of seconds to sleep before processing the next batch (default: 1).'
,
type
=
int
,
default
=
1
,
)
def
handle
(
self
,
*
args
,
**
options
):
batch_size
=
options
[
'batch_size'
]
sleep_time
=
options
[
'sleep'
]
offset
=
options
[
'offset'
]
max_pk
=
Answer
.
objects
.
order_by
(
'-pk'
)[
0
]
.
pk
batch_start
=
offset
batch_stop
=
batch_start
+
batch_size
self
.
stdout
.
write
(
"Copying Answer.course_id field into Answer.course_key in batches of at most {}"
.
format
(
batch_size
)
)
while
batch_start
<=
max_pk
:
queryset
=
Answer
.
objects
.
filter
(
pk__gte
=
batch_start
,
pk__lt
=
batch_stop
,
)
.
filter
(
Q
(
course_key__isnull
=
True
)
|
Q
(
course_key
=
''
)
)
queryset
.
update
(
course_key
=
F
(
'course_id'
))
self
.
stdout
.
write
(
"Processed Answers through pk: {}, max pk: {}"
.
format
(
batch_stop
,
max_pk
)
)
if
batch_stop
<
max_pk
:
time
.
sleep
(
sleep_time
)
batch_start
=
batch_stop
batch_stop
+=
batch_size
self
.
stdout
.
write
(
"Successfully copied Answer.course_id into Answer.course_key"
)
problem_builder/migrations/0006_remove_deprecated_course_id.py
0 → 100644
View file @
df221117
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-09-19 13:57
from
__future__
import
unicode_literals
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'problem_builder'
,
'0005_auto_20170112_1021'
),
]
operations
=
[
migrations
.
AlterUniqueTogether
(
name
=
'answer'
,
unique_together
=
set
([(
'student_id'
,
'course_key'
,
'name'
)]),
),
migrations
.
RemoveField
(
model_name
=
'answer'
,
name
=
'course_id'
,
),
]
setup.py
View file @
df221117
...
...
@@ -71,7 +71,7 @@ BLOCKS = [
setup
(
name
=
'xblock-problem-builder'
,
version
=
'2.7.
6
'
,
version
=
'2.7.
7
'
,
description
=
'XBlock - Problem Builder'
,
packages
=
find_packages
(),
install_requires
=
[
...
...
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