1+ from app .models import Base , Certificate
2+ from app .database import engine , SessionLocal
3+ from app .crud import create_certificate
4+ from app .schemas import CertificateCreate
5+
6+ # Create the database schema
7+ Base .metadata .create_all (bind = engine )
8+
9+ def seed_database ():
10+ db = SessionLocal ()
11+ try :
12+ certificates = [
13+ CertificateCreate (
14+ student_name = "John Doe" ,
15+ course_title = "Python Programming" ,
16+ completion_date = "2026-04-01" ,
17+ duration_hours = 40 ,
18+ issuer = "MathCodeLab" ,
19+ instructor = "Mohammad Orabe"
20+ ),
21+ CertificateCreate (
22+ student_name = "Jane Smith" ,
23+ course_title = "Data Science Basics" ,
24+ completion_date = "2026-03-15" ,
25+ duration_hours = 30 ,
26+ issuer = "MathCodeLab" ,
27+ instructor = "Mohammad Orabe"
28+ ),
29+ CertificateCreate (
30+ student_name = "Alice Johnson" ,
31+ course_title = "Advanced Java" ,
32+ completion_date = "2026-02-20" ,
33+ duration_hours = 50 ,
34+ issuer = "MathCodeLab" ,
35+ instructor = "Mohammad Orabe"
36+ )
37+ ]
38+
39+ for cert in certificates :
40+ create_certificate (db , cert )
41+
42+ print ("Database seeded successfully!" )
43+ except Exception as e :
44+ print (f"An error occurred while seeding the database: { e } " )
45+ finally :
46+ db .close ()
47+
48+ if __name__ == "__main__" :
49+ seed_database ()
0 commit comments