Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| from datetime import datetime | |
| # Add app to path | |
| sys.path.insert(0, os.path.abspath('.')) | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from app.core.database import Base, get_db, SessionLocal | |
| from app.models.user import User | |
| from app.models.goal import Goal | |
| from app.core.security import hash_password | |
| from app.core.config import settings | |
| def seed(): | |
| db = SessionLocal() | |
| try: | |
| # 1. Create User | |
| username = "testuser" | |
| existing = db.query(User).filter(User.user_id == username).first() | |
| if existing: | |
| print(f"User {username} already exists. Cleaning up old data...") | |
| db.delete(existing) | |
| db.commit() | |
| user = User( | |
| user_id=username, | |
| name="Test Explorer", | |
| email="test@example.com", | |
| hashed_password=hash_password("Password123"), | |
| coach_personality="supportive" | |
| ) | |
| db.add(user) | |
| db.commit() | |
| db.refresh(user) | |
| print(f"Created user: {username}") | |
| # 2. Create Goal | |
| # Note: We bypass LLM generation for speed by providing a mock plan_json | |
| mock_plan = { | |
| "goal": "Master Next.js & FastAPI", | |
| "duration_days": 30, | |
| "modules": [ | |
| { | |
| "title": "Module 1: Foundations", | |
| "duration_days": 7, | |
| "outcomes": ["Understand core concepts"], | |
| "tasks": [ | |
| {"title": "Setup development environment", "duration_min": 30, "deliverable": "Working dev server"}, | |
| {"title": "Learn FastAPI routing", "duration_min": 45, "deliverable": "Simple API"}, | |
| {"title": "Build Next.js components", "duration_min": 60, "deliverable": "UI Page"} | |
| ] | |
| } | |
| ], | |
| "meta": {"llm_used": False, "confidence": 1.0} | |
| } | |
| import json | |
| goal = Goal( | |
| user_id=user.user_id, | |
| goal_text="Master Next.js & FastAPI", | |
| category="coding", | |
| duration_days=30, | |
| plan_json=json.dumps(mock_plan), | |
| is_active=True | |
| ) | |
| db.add(goal) | |
| db.commit() | |
| print(f"Created goal: {goal.goal_text}") | |
| print("\n--- Seeding Complete! ---") | |
| print(f"Username: {username}") | |
| print(f"Password: Password123") | |
| except Exception as e: | |
| print(f"Error seeding data: {e}") | |
| finally: | |
| db.close() | |
| if __name__ == "__main__": | |
| seed() | |