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
10bd9e8a
Commit
10bd9e8a
authored
Oct 30, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/api-org-migration: Moved api_manager data migration work to orgs app
parent
777e2b97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
12 deletions
+52
-12
lms/djangoapps/organizations/migrations/0002_migrateorgdata.py
+52
-12
No files found.
lms/djangoapps/
api_manager/migrations/0014_auto__del_organization
.py
→
lms/djangoapps/
organizations/migrations/0002_migrateorgdata
.py
View file @
10bd9e8a
# -*- coding: utf-8 -*-
import
datetime
import
logging
from
south.db
import
db
from
south.v2
import
SchemaMigration
from
django.db
import
models
from
django.db
import
connection
,
models
,
transaction
from
organizations.models
import
Organization
log
=
logging
.
getLogger
(
__name__
)
class
Migration
(
SchemaMigration
):
def
print_message
(
self
,
msg
):
print
msg
log
.
info
(
msg
)
def
forwards
(
self
,
orm
):
# Deleting model 'Organization'
db
.
delete_table
(
'api_manager_organization'
)
if
not
db
.
dry_run
:
existing_entries
=
Organization
.
objects
.
all
()
.
count
()
self
.
print_message
(
'EXISTING ENTRIES: {}'
.
format
(
existing_entries
))
if
existing_entries
==
0
:
try
:
cursor
=
connection
.
cursor
()
cursor
.
execute
(
'INSERT INTO organizations_organization SELECT * from api_manager_organization'
)
log_msg
=
'organizations entries moved from api_manager to organizations app'
self
.
print_message
(
log_msg
)
cursor
.
execute
(
'INSERT INTO organizations_organization_workgroups '
'SELECT * from api_manager_organization_workgroups'
)
log_msg
=
'organization_workgroups entries moved from api_manager to organizations app'
self
.
print_message
(
log_msg
)
# Removing M2M table for field users on 'Organization'
db
.
delete_table
(
'api_manager_organization_users'
)
cursor
.
execute
(
'INSERT INTO organizations_organization_users '
'SELECT * from api_manager_organization_users'
)
log_msg
=
'organization_users entries moved from api_manager to organizations app'
self
.
print_message
(
log_msg
)
# Removing M2M table for field groups on 'Organization'
db
.
delete_table
(
'api_manager_organization_groups'
)
cursor
.
execute
(
'INSERT INTO organizations_organization_groups '
'SELECT * from api_manager_organization_groups'
)
log_msg
=
'organization_groups entries moved from api_manager to organizations app'
self
.
print_message
(
log_msg
)
transaction
.
commit
()
# Removing M2M table for field workgroups on
'Organization'
db
.
delete_table
(
'api_manager_organization_workgroups
'
)
# Deleting model
'Organization'
db
.
delete_table
(
'api_manager_organization
'
)
# Removing M2M table for field users on 'Organization'
db
.
delete_table
(
'api_manager_organization_users'
)
# Removing M2M table for field groups on 'Organization'
db
.
delete_table
(
'api_manager_organization_groups'
)
# Removing M2M table for field workgroups on 'Organization'
db
.
delete_table
(
'api_manager_organization_workgroups'
)
except
Exception
as
e
:
log_msg
=
e
.
message
self
.
print_message
(
log_msg
)
else
:
log_msg
=
'oroganizations_organization is not empty. You might have already filled it.'
self
.
print_message
(
log_msg
)
def
backwards
(
self
,
orm
):
# Adding model 'Organization'
...
...
@@ -60,7 +102,6 @@ class Migration(SchemaMigration):
))
db
.
create_unique
(
'api_manager_organization_workgroups'
,
[
'organization_id'
,
'workgroup_id'
])
models
=
{
'api_manager.coursecontentgrouprelationship'
:
{
'Meta'
:
{
'unique_together'
:
"(('course_id', 'content_id', 'group_profile'),)"
,
'object_name'
:
'CourseContentGroupRelationship'
},
...
...
@@ -158,4 +199,4 @@ class Migration(SchemaMigration):
}
}
complete_apps
=
[
'api_manager'
]
\ No newline at end of file
complete_apps
=
[
'api_manager'
]
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