From 406daeeab147e617818b1a2aee335bb07254db80 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Fri, 3 Apr 2026 10:30:56 -0400 Subject: [PATCH] Update transfer-questions CLI to accept user ID instead of username Co-Authored-By: Claude Opus 4.6 --- backend/app.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/app.py b/backend/app.py index 8a2cfe1..ceafadd 100644 --- a/backend/app.py +++ b/backend/app.py @@ -89,34 +89,36 @@ def create_app(config_name=None): return {'status': 'ok', 'message': 'Trivia Game API is running'}, 200 @app.cli.command('transfer-questions') - @click.argument('username') - def transfer_questions(username): + @click.argument('user_id', type=int) + def transfer_questions(user_id): """Transfer ownership of ALL questions to the specified user. - USERNAME is the preferred_username of the target user. + USER_ID is the database ID of the target user. """ from backend.models import User, Question - user = User.query.filter_by(preferred_username=username).first() + user = User.query.get(user_id) if not user: - click.echo(f"Error: No user found with username '{username}'") + click.echo(f"Error: No user found with id {user_id}") click.echo("Available users:") for u in User.query.all(): - click.echo(f" - {u.preferred_username} (id={u.id}, name={u.name})") + click.echo(f" - id={u.id}, name={u.name or u.preferred_username}") raise SystemExit(1) + display_name = user.name or user.preferred_username + count = Question.query.count() if count == 0: click.echo("No questions found in the database.") return - click.echo(f"This will transfer ownership of {count} question(s) to '{username}' (id={user.id}).") + click.echo(f"This will transfer ownership of {count} question(s) to '{display_name}' (id={user.id}).") if not click.confirm("Proceed?"): click.echo("Aborted.") return Question.query.update({Question.created_by: user.id}) db.session.commit() - click.echo(f"Successfully transferred {count} question(s) to '{username}'.") + click.echo(f"Successfully transferred {count} question(s) to '{display_name}'.") return app