Skip to content

Commit

Permalink
add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabtieu committed Dec 21, 2021
1 parent 1d2e157 commit c496049
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

msg = """Before migrating, please confirm the following:
- You are on v2.4.0 to v2.4.3 (older version please update to one of these first, new version no migrate necessary)
- You are on v3.0.0 to v3.0.1 (older version please update to one of these first, new version no migrate necessary)
- You have made a backup of the database
- You have write permissions in the current directory
Please note that migration is a one-way operation, and you will not be able to revert to the previous version without a backup.
Expand All @@ -16,7 +16,19 @@

db = cs50.SQL("sqlite:///database.db")

## TODO: add missing submissions from contest problem exports
db.execute("ALTER TABLE contest_users ADD COLUMN 'hidden' integer NOT NULL DEFAULT(0)")
db.execute('ALTER TABLE contest_users ADD COLUMN "hidden" integer NOT NULL DEFAULT(0)')

exportable = db.execute('SELECT * FROM submissions WHERE contest_id IS NOT NULL')
problem_ids = set([e['id'] for e in db.execute('SELECT id FROM problems')])
i = 1
for sub in exportable:
print(f'Duplicating submission {i} of {len(exportable)}')
i += 1
exported_id = sub['contest_id'] + '-' + sub['problem_id']
if exported_id not in problem_ids:
continue
db.execute(('INSERT INTO submissions(date, user_id, problem_id, correct, submitted) '
'VALUES(?, ?, ?, ?, ?)'), sub['date'], sub['user_id'], exported_id,
sub['correct'], sub['submitted'])

print('Migration completed.')

0 comments on commit c496049

Please sign in to comment.