diff --git a/app/__init__.py b/app/__init__.py index 2b6c71f..7da0659 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -75,7 +75,7 @@ def inject_globals(): } with app.app_context(): - from app.seed import seed_db + from app.models import seed_db # Reset database if app.config["RESET_DB"]: diff --git a/app/models/__init__.py b/app/models/__init__.py index 77f1da1..e8cdf5b 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -27,3 +27,24 @@ def seed(cls, db: SQLAlchemy, fake: Optional[Faker] = None) -> None: from .therapy_exercise import TherapyExercise from .title import Title from .user import User + + +# Seed required models in order +def seed_db(db: SQLAlchemy, use_fake_data: bool) -> None: + Title.seed(db) + Language.seed(db) + Issue.seed(db) + Intervention.seed(db) + + if use_fake_data: + fake = Faker() + User.seed(db, fake) + Therapist.seed(db, fake) + Client.seed(db, fake) + Conversation.seed(db) + Message.seed(db, fake) + AppointmentType.seed(db, fake) + Appointment.seed(db, fake) + AppointmentNotes.seed(db, fake) + TherapyExercise.seed(db, fake) + return diff --git a/app/seed.py b/app/seed.py deleted file mode 100644 index 8b23bc6..0000000 --- a/app/seed.py +++ /dev/null @@ -1,37 +0,0 @@ -from faker import Faker -from flask_sqlalchemy import SQLAlchemy - -from app.models.appointment import Appointment -from app.models.appointment_notes import AppointmentNotes -from app.models.appointment_type import AppointmentType -from app.models.client import Client -from app.models.conversation import Conversation -from app.models.intervention import Intervention -from app.models.issue import Issue -from app.models.language import Language -from app.models.message import Message -from app.models.therapist import Therapist -from app.models.therapy_exercise import TherapyExercise -from app.models.title import Title -from app.models.user import User - - -# Seed required models in order -def seed_db(db: SQLAlchemy, use_fake_data: bool) -> None: - Title.seed(db) - Language.seed(db) - Issue.seed(db) - Intervention.seed(db) - - if use_fake_data: - fake = Faker() - User.seed(db, fake) - Therapist.seed(db, fake) - Client.seed(db, fake) - Conversation.seed(db) - Message.seed(db, fake) - AppointmentType.seed(db, fake) - Appointment.seed(db, fake) - AppointmentNotes.seed(db, fake) - TherapyExercise.seed(db, fake) - return