illinois-cs241 / broadway-on-demand

Webapp that facilitates on-demand assignment autograding via Broadway.
Other
11 stars 4 forks source link

Merge admin staff ids #128

Closed ameyagh closed 3 years ago

ameyagh commented 3 years ago

Changed db.py code to be able to access database for the new schema. Merged admin_ids and staff_ids.

Xiangmingchen commented 3 years ago

Can you also post the script to migrate db here?

ameyagh commented 3 years ago

Can you also post the script to migrate db here?


import pymongo
from pymongo import MongoClient

client = MongoClient() db = client['broadway_on_demand']

update this with the course we are trying to fix

_ID = 'test-course'

get courses

courses = list(db.courses.find({'staff_ids': {'$exists': True}}))

def find_course(_ID, courses): for course in courses: if course['_id'] == _ID: return course

return None

course = find_course(_ID, courses)

get admin_ids/staff_ids

admin_ids = course['admin_ids'] staff_ids = course['staff_ids']

staff = {'staff': {}}

add staff_ids to total dict

for staff_id in staff_ids: staff['staff'][staff_id] = {'is_admin': False}

add admin_ids to total dict

for admin_id in admin_ids: staff['staff'][admin_id] = {'is_admin': True}

try:

add the new staff document

db.courses.update_one({'_id': _ID}, {'$set': staff})
# get rid of the staff_ids list
db.courses.update_one({'_id': _ID}, {'$unset': {'staff_ids': 1}})
# get rid of the admin_ids list
db.courses.update_one({'_id': _ID}, {'$unset': {'admin_ids': 1}})

print('Merged admin_ids and staff_ids')

except: print('Something when wrong')