import os import uuid import sys sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "backend"))) from core.subscription.db import SessionLocal from core.projects.models import Project, ProjectSection from core.subscription.models import User from scripts.seed_section_templates import TEMPLATES, ProjectSectionTemplate db = SessionLocal() try: clerk_id = "test_user_" + str(uuid.uuid4())[:8] user = User(clerk_id=clerk_id) db.add(user) db.commit() db.refresh(user) new_project = Project( id=str(uuid.uuid4()), clerk_user_id=clerk_id, title="Test Titla", program_type="SMART", status="draft", ) db.add(new_project) db.flush() templates = ( db.query(ProjectSectionTemplate) .filter(ProjectSectionTemplate.program_type == "SMART") .order_by(ProjectSectionTemplate.order.asc()) .all() ) if not templates: for tmpl in TEMPLATES: new_template = ProjectSectionTemplate(**tmpl) db.add(new_template) db.commit() templates = ( db.query(ProjectSectionTemplate) .filter(ProjectSectionTemplate.program_type == "SMART") .order_by(ProjectSectionTemplate.order.asc()) .all() ) for tmpl in templates: sec = ProjectSection( project_id=new_project.id, section_type=tmpl.section_type, order=tmpl.order, content="", is_approved=False, generated_by_ai=False, ) db.add(sec) db.commit() print("SUCCESS: Project created!") except Exception: import traceback traceback.print_exc() finally: db.close()