Files
habit-tracker/scripts/claim_orphan_habits.py
T
shinalokandClaude Sonnet 5 cee589bb3e Initial commit: habit tracker PWA with Google OAuth, push notifications
FastAPI + SQLAlchemy/Alembic + MariaDB backend with Jinja2/htmx/Alpine
server-rendered frontend. Multi-user via Google OAuth, daily habit
tracking, monthly/weekly history views, Web Push reminders via
APScheduler, and PWA support (manifest, service worker, offline caching).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-16 18:06:17 +09:00

35 lines
1.1 KiB
Python

"""PIN 로그인 시절부터 쌓인, 소유자 없는(user_id IS NULL) 습관을 지정한 이메일의 계정으로 연결합니다.
먼저 구글 로그인을 한 번 해서 계정이 생성된 뒤에 실행하세요.
사용법:
python scripts/claim_orphan_habits.py <이메일>
"""
import sys
from sqlalchemy import select, update
from app.database import SessionLocal
from app.models.habit import Habit
from app.models.user import User
if __name__ == "__main__":
if len(sys.argv) != 2:
raise SystemExit("사용법: python scripts/claim_orphan_habits.py <이메일>")
email = sys.argv[1]
db = SessionLocal()
try:
user = db.scalar(select(User).where(User.email == email))
if user is None:
raise SystemExit(f"'{email}' 계정을 찾을 수 없습니다. 먼저 구글 로그인을 한 번 해주세요.")
result = db.execute(
update(Habit).where(Habit.user_id.is_(None)).values(user_id=user.id)
)
db.commit()
print(f"{result.rowcount}개의 습관을 '{email}' 계정으로 연결했습니다.")
finally:
db.close()