Tanzania-AI-Community / twiga

Twiga is a WhatsApp bot for Tanzanian educators.
https://ai.or.tz/
MIT License
6 stars 5 forks source link

Add validation to database table models #41

Open jurmy24 opened 3 hours ago

jurmy24 commented 3 hours ago

Don't know how to do it right now but I want the following validations in the database models in the file app/database/models.py:

In the User model I want this:

state VARCHAR(15) CHECK (state IN ('onboarding', 'ai_lessons', 'active', 'settings')),
 role VARCHAR(20) DEFAULT 'teacher' CHECK (role IN ('teacher', 'admin', 'student')),

In the Class model I want this: grade_level INT NOT NULL CHECK (grade_level BETWEEN 1 AND 13),

jurmy24 commented 3 hours ago

I'm quite flexible regarding exactly what Literals are allowed (such as teacher, admin, student, etc...). It's more about making sure the validations work with SQLModel as it should and doesn't cause any issues with migrations and whatnot.