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
ec6eccce
Commit
ec6eccce
authored
Mar 07, 2016
by
Kevin Falcone
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11748 from edx/jibsheet/course_overview_0009_on_migrate_from_scratch
Migrate correctly from scratch also
parents
dbc2b416
631bfc08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
openedx/core/djangoapps/content/course_overviews/migrations/0009_readd_facebook_url.py
+30
-9
No files found.
openedx/core/djangoapps/content/course_overviews/migrations/0009_readd_facebook_url.py
View file @
ec6eccce
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
,
OperationalError
,
connection
from
django.db
import
migrations
,
models
,
connection
from
openedx.core.djangoapps.content.course_overviews.models
import
CourseOverview
def
table_description
():
"""Handle Mysql/Pg vs Sqlite"""
# django's mysql/pg introspection.get_table_description tries to select *
# from table and fails during initial migrations from scratch.
# sqlite does not have this failure, so we can use the API.
# For not-sqlite, query information-schema directly with code lifted
# from the internals of django.db.backends.mysql.introspection.py
if
connection
.
vendor
==
'sqlite'
:
fields
=
connection
.
introspection
.
get_table_description
(
connection
.
cursor
(),
'course_overviews_courseoverview'
)
return
[
f
.
name
for
f
in
fields
]
else
:
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'course_overviews_courseoverview' AND table_schema = DATABASE()"""
)
rows
=
cursor
.
fetchall
()
return
[
r
[
0
]
for
r
in
rows
]
class
Migration
(
migrations
.
Migration
):
class
Migration
(
migrations
.
Migration
):
...
@@ -11,15 +30,17 @@ class Migration(migrations.Migration):
...
@@ -11,15 +30,17 @@ class Migration(migrations.Migration):
(
'course_overviews'
,
'0008_remove_courseoverview_facebook_url'
),
(
'course_overviews'
,
'0008_remove_courseoverview_facebook_url'
),
]
]
# An original version of 0008 removed the facebook_url field
# An original version of 0008 removed the facebook_url field We need to
# We need to handle the case where our noop 0008 ran AND the case
# handle the case where our noop 0008 ran AND the case where the original
# where the original 0008 ran. We do that by using Django's introspection
# 0008 ran. We do that by using the standard information_schema to find out
# API to query INFORMATION_SCHEMA. _meta is unavailable as the
# what columns exist. _meta is unavailable as the column has already been
# column has already been removed from the model.
# removed from the model
fields
=
connection
.
introspection
.
get_table_description
(
connection
.
cursor
(),
'course_overviews_courseoverview'
)
operations
=
[]
operations
=
[]
fields
=
table_description
()
if
not
any
(
f
.
name
==
'facebook_url'
for
f
in
fields
):
# during a migration from scratch, fields will be empty, but we do not want to add
# an additional facebook_url
if
fields
and
not
any
(
f
==
'facebook_url'
for
f
in
fields
):
operations
+=
migrations
.
AddField
(
operations
+=
migrations
.
AddField
(
model_name
=
'courseoverview'
,
model_name
=
'courseoverview'
,
name
=
'facebook_url'
,
name
=
'facebook_url'
,
...
...
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