Spaces:
Sleeping
Sleeping
File size: 5,475 Bytes
4518498 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | 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())
|