Commit ddcfd699 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Migration script fixes. [skip ci]

parent 6b5945a0
Pipeline #52029 skipped
......@@ -74,8 +74,8 @@ def chown(ctx, user, uploads):
print('%d uploads selected, changing its owner ...' % uploads.count())
user_id = str(user)
user = coe_repo.User.from_user_id(user_id)
user_id = user
user = coe_repo.User.from_user_id(int(user_id))
for upload in uploads:
upload.user_id = user_id
......@@ -81,6 +81,8 @@ while True:
for upload, (dup, single) in upload_dict.items():
if dup > 0:
package_id = uploads.find_one({'_id': upload})['name']
source_upload_id = packages.find_one({'_id': package_id})['upload_id']
print('%s, %s, %s (%d vs %d)' % (source_upload_id, package_id, upload, dup, single))
pkg = packages.find_one({'_id': package_id})
source_upload_id = pkg['upload_id']
pkg_path = pkg['package_path']
print('%s, %s, %s, %s (%d vs %d)' % (source_upload_id, package_id, pkg_path, upload, dup, single))
......@@ -11,24 +11,17 @@ infrastructure.setup_elastic()
def check_and_fix(upload):
example = calcs.find_one({'upload_id': upload, '': {'$exists': True}})
if example is None:
# can happen on multi package uploads
pid = example['metadata']['pid']
truth = index.find_one({'_id': pid})
if truth['metadata']['with_embargo'] != example['metadata']['with_embargo']:
print('need to fix %s' % upload)
{'upload_id': upload, 'metadata.with_embargo': True},
{'$set': {'changed': True, 'metadata.with_embargo': False}})
{'upload_id': upload, 'metadata.with_embargo': False, 'changed': True},
{'$unset': {'changed': 1}, '$set': {'metadata.with_embargo': True}})
u = uploads_col.find_one({'_id': upload})
print('need to fix from user %d, %s package id %s' % (example['metadata']['uploader']['id'], upload, u['name']))
upload_proc = processing.Upload.get_by_id(upload)
upload_with_metadata = upload_proc.to_upload_with_metadata(upload_proc.metadata)
calcs_with_metadata = upload_with_metadata.calcs
for upload in calcs.distinct('upload_id'):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment