Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lti-xblock-consumer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
OpenJupyter
lti-xblock-consumer
Commits
1552134f
Commit
1552134f
authored
4 years ago
by
stvn
Browse files
Options
Downloads
Plain Diff
Merge PR #144 bd03/fix-migration
* Commits: fix: Manually backfill config_id UUIDs again
parents
20fb1ed4
42a9e342
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lti_consumer/migrations/0009_backfill-empty-string-config-id.py
+72
-0
72 additions, 0 deletions
...nsumer/migrations/0009_backfill-empty-string-config-id.py
with
72 additions
and
0 deletions
lti_consumer/migrations/0009_backfill-empty-string-config-id.py
0 → 100644
+
72
−
0
View file @
1552134f
"""
Backfill empty config_id records
We need to do this with raw SQL,
otherwise the model fails upon instantiation,
as the empty string is an invalid UUID.
"""
import
uuid
from
django.db
import
connection
from
django.db
import
migrations
sql_forward
=
"""
\
UPDATE
lti_consumer_lticonfiguration
SET
config_id = %s
WHERE
id = %s
;
\
"""
sql_select_empty
=
"""
\
SELECT
id
FROM
lti_consumer_lticonfiguration
WHERE
config_id =
""
;
\
"""
def
_get_ids_with_empty_uuid
():
"""
Retrieve the list of primary keys for each entry with a blank config_id
"""
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
sql_select_empty
)
for
row
in
cursor
.
fetchall
():
yield
row
[
0
]
def
_create_config_ids
(
apps
,
schema_editor
):
"""
Generate a UUID for rows missing one
Note: The model stores these without hyphens.
"""
for
_id
in
_get_ids_with_empty_uuid
():
config_id
=
uuid
.
uuid4
()
config_id
=
str
(
config_id
)
config_id
=
config_id
.
replace
(
'
-
'
,
''
)
schema_editor
.
execute
(
sql_forward
,
[
config_id
,
_id
,
])
class
Migration
(
migrations
.
Migration
):
"""
Backfill empty config_id records
"""
dependencies
=
[
(
'
lti_consumer
'
,
'
0008_fix_uuid_backfill
'
),
]
operations
=
[
migrations
.
RunPython
(
_create_config_ids
,
atomic
=
False
),
]
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