| """ |
| DRP Backend — Seed Data |
| Populates the database with prototype data: 1 school, 2 classes, 2 teachers, 18 books, 6 clusters. |
| """ |
| import hashlib, sys, os |
| sys.path.insert(0, os.path.dirname(__file__)) |
|
|
| from database import engine, SessionLocal, Base |
| from models import * |
|
|
| def _hash(pin): return hashlib.sha256(pin.encode()).hexdigest() |
|
|
| def seed(): |
| Base.metadata.create_all(bind=engine) |
| db = SessionLocal() |
|
|
| |
| prog = Programme(programme_id="prog-1", name="Gujarat Digital Reading Programme 2026", state_code="GJ", year=2026) |
| db.add(prog) |
|
|
| |
| dist = District(district_id="dist-surat", name="Surat", state_code="GJ") |
| db.add(dist) |
|
|
| |
| school = School(school_id="school-1", udise_code="2430101001", name="Surat Municipal School #7", |
| district_id="dist-surat", block="Athwa", programme_id="prog-1", |
| whatsapp_group_link="https://chat.whatsapp.com/demo-surat-school-7") |
| db.add(school) |
|
|
| |
| c3a = ClassAccount(class_id="class-3a", school_id="school-1", grade=3, section="A", year=2026) |
| c5b = ClassAccount(class_id="class-5b", school_id="school-1", grade=5, section="B", year=2026) |
| db.add_all([c3a, c5b]) |
|
|
| |
| t1 = TeacherAccount(teacher_id="teacher-meera", name="Meera Shah", phone="9876543210", |
| email="meera@school.in", password_hash=_hash("teacher123"), |
| school_id="school-1", activation_token="meera-token-123", is_active=True) |
| t2 = TeacherAccount(teacher_id="teacher-rajesh", name="Rajesh Patel", phone="9876543211", |
| email="rajesh@school.in", password_hash=_hash("teacher123"), |
| school_id="school-1", activation_token="rajesh-token-456", is_active=True) |
| db.add_all([t1, t2]) |
|
|
| |
| db.add(TeacherClassMapping(teacher_id="teacher-meera", class_id="class-3a", role="primary", is_default=True)) |
| db.add(TeacherClassMapping(teacher_id="teacher-meera", class_id="class-5b", role="secondary", is_default=False)) |
| db.add(TeacherClassMapping(teacher_id="teacher-rajesh", class_id="class-5b", role="primary", is_default=True)) |
|
|
| |
| db.add(AdminAccount(admin_id="admin-school", name="Priya Desai", email="school@drp.in", |
| password_hash=_hash("admin123"), role="school_admin", school_id="school-1")) |
| db.add(AdminAccount(admin_id="admin-district", name="Amit Mehta", email="district@drp.in", |
| password_hash=_hash("admin123"), role="district_admin", district_id="dist-surat")) |
| db.add(AdminAccount(admin_id="admin-state", name="Kavita Sharma", email="state@drp.in", |
| password_hash=_hash("admin123"), role="state_admin", state_code="GJ")) |
| db.add(AdminAccount(admin_id="admin-programme", name="Rohan Gupta", email="programme@drp.in", |
| password_hash=_hash("admin123"), role="programme_team")) |
|
|
| |
| books_data = [ |
| |
| ("b-1-1", "The Friendly Elephant", "Sunita Rao", 1, "Animals", True, |
| "What did the elephant do when he saw the mouse?", |
| {"question": "Why was the elephant friendly?", "options": ["He was lonely", "He liked making friends", "He was hungry", "He was scared"], "correct": "He liked making friends"}, |
| {"question": "What sound does an elephant make?", "options": ["Meow", "Trumpet", "Bark", "Chirp"], "correct": "Trumpet"}), |
| ("b-1-2", "The Clever Crow", "Anil Kumar", 1, "Animals", True, |
| "Have you ever seen a crow do something clever?", |
| {"question": "How did the crow get water?", "options": ["Asked for help", "Dropped pebbles", "Broke the pot", "Waited for rain"], "correct": "Dropped pebbles"}, |
| {"question": "Complete: Clever as a ___", "options": ["Fox", "Crow", "Cat", "Owl"], "correct": "Crow"}), |
| ("b-1-3", "The Singing Fish", "Meena Iyer", 1, "Animals", True, |
| "Can fish really sing? What do you think?", |
| {"question": "Where did the fish live?", "options": ["River", "Ocean", "Pond", "Aquarium"], "correct": "Pond"}, |
| {"question": "What made the fish happy?", "options": ["Food", "Singing", "Swimming", "Sleeping"], "correct": "Singing"}), |
| |
| ("b-1-4", "The Mango Tree", "Vikram Shah", 1, "Nature", True, |
| "Do you have a favourite tree near your house?", |
| {"question": "When do mangoes ripen?", "options": ["Winter", "Summer", "Monsoon", "Spring"], "correct": "Summer"}, |
| {"question": "What colour is a ripe mango?", "options": ["Green", "Yellow", "Blue", "White"], "correct": "Yellow"}), |
| ("b-1-5", "Rain, Rain, Come Again", "Priya Nair", 1, "Nature", True, |
| "What do you like to do when it rains?", |
| {"question": "What comes after rain?", "options": ["Snow", "Rainbow", "Thunder", "Night"], "correct": "Rainbow"}, |
| {"question": "Finish: Pitter patter ___", "options": ["Rain drops", "Sun shine", "Wind blow", "Stars twinkle"], "correct": "Rain drops"}), |
| ("b-1-6", "The Little Seed", "Geeta Menon", 1, "Nature", True, |
| "Have you ever planted a seed?", |
| {"question": "What does a seed need to grow?", "options": ["Only water", "Water and sunlight", "Only soil", "Nothing"], "correct": "Water and sunlight"}, |
| {"question": "What grows from a seed?", "options": ["Rock", "Plant", "Animal", "Cloud"], "correct": "Plant"}), |
| |
| ("b-1-7", "My Best Friend", "Ravi Sharma", 1, "Friendship", True, |
| "Who is your best friend and why?", |
| {"question": "What makes a good friend?", "options": ["Being rich", "Being kind", "Being tall", "Being fast"], "correct": "Being kind"}, |
| {"question": "How many friends did Ritu have?", "options": ["None", "One", "Two", "Many"], "correct": "Many"}), |
| ("b-1-8", "Sharing is Caring", "Anita Desai", 1, "Friendship", True, |
| "When was the last time you shared something?", |
| {"question": "What did Aman share?", "options": ["His lunch", "His toy", "His book", "His pencil"], "correct": "His lunch"}, |
| {"question": "Sharing makes us feel ___", "options": ["Sad", "Angry", "Happy", "Tired"], "correct": "Happy"}), |
| ("b-1-9", "The New Student", "Kavita Joshi", 1, "Friendship", True, |
| "How would you welcome a new student?", |
| {"question": "Why was Nisha nervous?", "options": ["New school", "Exam", "Sports day", "Holiday"], "correct": "New school"}, |
| {"question": "Who helped Nisha?", "options": ["Teacher", "Her classmates", "Principal", "No one"], "correct": "Her classmates"}), |
| |
| ("b-3-1", "The Asiatic Lion's Journey", "Deepak Rao", 3, "Animals", False, |
| "Why are Asiatic lions found only in Gujarat?", |
| {"question": "Where is the Gir Forest?", "options": ["Rajasthan", "Gujarat", "Maharashtra", "Kerala"], "correct": "Gujarat"}, |
| {"question": "What threatens the lion population?", "options": ["Floods", "Habitat loss", "Cold weather", "Other animals"], "correct": "Habitat loss"}), |
| ("b-3-2", "Wings Over the Wetlands", "Sameera Khan", 3, "Animals", False, |
| "Have you seen migratory birds near your town?", |
| {"question": "Why do birds migrate?", "options": ["For fun", "To find food and warmth", "They are lost", "To meet friends"], "correct": "To find food and warmth"}, |
| {"question": "Which wetland is famous in Gujarat?", "options": ["Chilika", "Nal Sarovar", "Dal Lake", "Loktak"], "correct": "Nal Sarovar"}), |
| ("b-3-3", "The Desert Fox", "Mohan Bhatt", 3, "Animals", False, |
| "How do animals survive in the desert?", |
| {"question": "How does the desert fox stay cool?", "options": ["Swimming", "Large ears release heat", "Staying underground all day", "Drinking lots of water"], "correct": "Large ears release heat"}, |
| {"question": "Desert foxes are most active at ___", "options": ["Morning", "Afternoon", "Night", "Noon"], "correct": "Night"}), |
| |
| ("b-3-4", "The Water Cycle", "Nandini Patel", 3, "Nature", False, |
| "Where does rain come from?", |
| {"question": "What is evaporation?", "options": ["Water freezing", "Water turning to vapor", "Rain falling", "Rivers flowing"], "correct": "Water turning to vapor"}, |
| {"question": "Clouds are made of tiny ___", "options": ["Dust", "Water droplets", "Air bubbles", "Smoke"], "correct": "Water droplets"}), |
| ("b-3-5", "Forests of India", "Arjun Nair", 3, "Nature", False, |
| "Why are forests called the lungs of the Earth?", |
| {"question": "Trees produce ___", "options": ["Carbon dioxide", "Oxygen", "Nitrogen", "Hydrogen"], "correct": "Oxygen"}, |
| {"question": "What is deforestation?", "options": ["Planting trees", "Cutting down forests", "Watering plants", "Forest fires"], "correct": "Cutting down forests"}), |
| ("b-3-6", "The Mighty Narmada", "Rekha Sharma", 3, "Nature", False, |
| "Do you know any rivers near your city?", |
| {"question": "Where does the Narmada originate?", "options": ["Himalayas", "Amarkantak", "Western Ghats", "Vindhyas"], "correct": "Amarkantak"}, |
| {"question": "The Narmada flows into the ___", "options": ["Bay of Bengal", "Arabian Sea", "Indian Ocean", "Pacific Ocean"], "correct": "Arabian Sea"}), |
| |
| ("b-3-7", "The Pen Pal Project", "Sneha Kulkarni", 3, "Friendship", False, |
| "Would you like to have a pen pal from another state?", |
| {"question": "What did Arya learn from her pen pal?", "options": ["Math", "A new language and culture", "Science", "Sports"], "correct": "A new language and culture"}, |
| {"question": "Pen pals communicate through ___", "options": ["Telepathy", "Letters or emails", "Sign language", "Morse code"], "correct": "Letters or emails"}), |
| ("b-3-8", "Standing Up Together", "Farhan Ali", 3, "Friendship", False, |
| "Have you ever stood up for a friend?", |
| {"question": "What is bullying?", "options": ["Playing together", "Hurting someone repeatedly", "Sharing food", "Helping others"], "correct": "Hurting someone repeatedly"}, |
| {"question": "The best way to stop bullying is ___", "options": ["Ignore it", "Join in", "Tell a trusted adult", "Fight back"], "correct": "Tell a trusted adult"}), |
| ("b-3-9", "Different But Equal", "Lakshmi Rao", 3, "Friendship", False, |
| "What makes each person unique and special?", |
| {"question": "What does inclusion mean?", "options": ["Leaving people out", "Including everyone", "Being the same", "Competing"], "correct": "Including everyone"}, |
| {"question": "Diversity makes our world ___", "options": ["Confusing", "Boring", "Richer", "Difficult"], "correct": "Richer"}), |
| ] |
|
|
| for bd in books_data: |
| book = Book(book_id=bd[0], title=bd[1], author=bd[2], level=bd[3], theme=bd[4], |
| has_readalong=bd[5], activity_lets_talk=bd[6], |
| activity_lets_understand=bd[7], activity_lets_play=bd[8], |
| pages=[{"page_num": i+1, "text": f"Page {i+1} of {bd[1]}", "image_url": None} for i in range(6)]) |
| db.add(book) |
|
|
| |
| clusters = [ |
| ("cl-l1-animals", 3, 1, "Animals", ["b-1-1","b-1-2","b-1-3"], "All creatures great and small"), |
| ("cl-l1-nature", 3, 1, "Nature", ["b-1-4","b-1-5","b-1-6"], "Growing things around us"), |
| ("cl-l1-friendship", 3, 1, "Friendship", ["b-1-7","b-1-8","b-1-9"], "Being there for each other"), |
| ("cl-l3-animals", 5, 3, "Animals", ["b-3-1","b-3-2","b-3-3"], "Wildlife of India"), |
| ("cl-l3-nature", 5, 3, "Nature", ["b-3-4","b-3-5","b-3-6"], "Our natural world"), |
| ("cl-l3-friendship", 5, 3, "Friendship", ["b-3-7","b-3-8","b-3-9"], "Bonds that matter"), |
| ] |
| for cd in clusters: |
| db.add(Cluster(cluster_id=cd[0], grade=cd[1], level=cd[2], theme=cd[3], book_ids=cd[4], connecting_thread=cd[5])) |
|
|
| |
| from datetime import datetime, timedelta |
| for i in range(24): |
| db.add(SystemHealthLog(timestamp=datetime.utcnow() - timedelta(hours=i), |
| api_latency_ms=45 + (i % 5) * 10, error_count=i % 3, |
| active_sessions=max(0, 10 - i), sync_queue_depth=i % 2, uptime_percent=99.9)) |
|
|
| |
| fs1 = FieldStaff(staff_id="staff-1", name="Vikram Thakor", phone="9898989898", |
| email="vikram@drp.in", password_hash=_hash("staff123"), |
| district_id="dist-surat", assigned_blocks=["Athwa", "Katargam"]) |
| db.add(fs1) |
| db.add(SchoolStaffMapping(staff_id="staff-1", school_id="school-1", is_primary=True)) |
|
|
| db.commit() |
| db.close() |
| print("[OK] Database seeded successfully! (v3)") |
| print(" - 1 Programme, 1 District, 1 School") |
| print(" - 2 Classes: 3-A, 5-B") |
| print(" - 2 Teachers: Meera Shah, Rajesh Patel") |
| print(" - 18 Books, 6 Clusters") |
| print(" - 4 Admin accounts (all password: admin123)") |
| print(" - 1 Field Staff: Vikram Thakor") |
| print(" Teacher logins:") |
| print(" Meera: OTP 9876543210 | Email meera@school.in / teacher123") |
| print(" Rajesh: OTP 9876543211 | Email rajesh@school.in / teacher123") |
| print(" Field Staff login: vikram@drp.in / staff123") |
| print(" Admin login (all): school@drp.in, district@drp.in, state@drp.in, programme@drp.in / admin123") |
|
|
| if __name__ == "__main__": |
| seed() |
|
|