import asyncio import uuid import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from app.database import engine from app.models.user import User from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import sessionmaker from sqlalchemy import delete # Standardized BCA Semester 3 Topic Tree for GGSIPU bca_topic_tree = [ { "subject": "Database Management Systems", "subject_code": "BCA-301", "credits": 4, "units": [ { "unit_id": "u1", "title": "Introduction to DBMS", "topics": [ {"topic_id": "u1t1", "id": "u1t1", "name": "What is a database", "weight": "high"}, {"topic_id": "u1t2", "id": "u1t2", "name": "DBMS vs File System", "weight": "medium"}, {"topic_id": "u1t3", "id": "u1t3", "name": "Data Models", "weight": "high"} ] }, { "unit_id": "u2", "title": "Relational Model", "topics": [ {"topic_id": "u2t1", "id": "u2t1", "name": "Relational Algebra", "weight": "high"}, {"topic_id": "u2t2", "id": "u2t2", "name": "Integrity Constraints", "weight": "medium"} ] } ] }, { "subject": "Data Structures", "subject_code": "BCA-302", "credits": 4, "units": [ { "unit_id": "u1", "title": "Arrays and Linked Lists", "topics": [ {"topic_id": "u1t1", "id": "u1t1", "name": "1D and 2D Arrays", "weight": "high"}, {"topic_id": "u1t2", "id": "u1t2", "name": "Singly Linked List", "weight": "high"}, {"topic_id": "u1t3", "id": "u1t3", "name": "Doubly Linked List", "weight": "medium"} ] } ] }, { "subject": "Computer Networks", "subject_code": "BCA-303", "credits": 4, "units": [ { "unit_id": "u1", "title": "OSI Model", "topics": [ {"topic_id": "u1t1", "id": "u1t1", "name": "Physical Layer", "weight": "low"}, {"topic_id": "u1t2", "id": "u1t2", "name": "Data Link Layer", "weight": "high"}, {"topic_id": "u1t3", "id": "u1t3", "name": "Network Layer", "weight": "high"} ] } ] }, { "subject": "Operating Systems", "subject_code": "BCA-304", "credits": 4, "units": [ { "unit_id": "u1", "title": "Process Management", "topics": [ {"topic_id": "u1t1", "id": "u1t1", "name": "Process States", "weight": "high"}, {"topic_id": "u1t2", "id": "u1t2", "name": "Scheduling Algorithms", "weight": "high"} ] } ] }, { "subject": "Object Oriented Programming (Java)", "subject_code": "BCA-305", "credits": 4, "units": [ { "unit_id": "u1", "title": "Basics of OOP", "topics": [ {"topic_id": "u1t1", "id": "u1t1", "name": "Classes and Objects", "weight": "high"}, {"topic_id": "u1t2", "id": "u1t2", "name": "Inheritance", "weight": "high"}, {"topic_id": "u1t3", "id": "u1t3", "name": "Polymorphism", "weight": "medium"} ] } ] } ] async def seed_data(): async_session = sessionmaker( engine, class_=AsyncSession, expire_on_commit=False ) async with async_session() as session: # Define seed test user phone numbers bca_student_phone = "+919999999999" new_student_phone = "+918888888888" # 1. Clean up existing test users if they exist to avoid unique constraint violations print("Cleaning up old test users...") await session.execute(delete(User).where(User.phone.in_([bca_student_phone, new_student_phone]))) await session.commit() # 2. Instantiate new test users users = [ # Pre-onboarded BCA student with full syllabus tree populated User( id=uuid.uuid4(), phone=bca_student_phone, name="BCA Scholar", age_verified=True, age=20, university_name="Guru Gobind Singh Indraprastha University (GGSIPU)", course="BCA", semester=3, has_syllabus=True, syllabus_data=bca_topic_tree, onboarding_complete=True, tier="free" ), # Fresh user for testing onboarding / setup flow User( id=uuid.uuid4(), phone=new_student_phone, name="New Student", age_verified=True, age=19, onboarding_complete=False, tier="free" ) ] session.add_all(users) await session.commit() print(f"Database seeded successfully with test users: {bca_student_phone} (Pre-onboarded BCA) and {new_student_phone} (Clean state)!") if __name__ == "__main__": asyncio.run(seed_data())