diff --git a/app/main.py b/app/main.py index 958d6b5..9f99831 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,12 @@ from fastapi import FastAPI from .controllers import userManager, cardManager +from .services.database import create_db_and_tables app = FastAPI() +@app.on_event("startup") +def on_startup(): + create_db_and_tables() + print("Database created and tables initialized.") + app.include_router(userManager.user_router) app.include_router(cardManager.card_router) \ No newline at end of file diff --git a/app/services/database.py b/app/services/database.py index 0fa6374..1c76bd0 100644 --- a/app/services/database.py +++ b/app/services/database.py @@ -5,4 +5,6 @@ from ..model.models import Base SQLALCHEMY_DATABASE_URL = "sqlite:///./gatekeeper.db" engine = create_engine(SQLALCHEMY_DATABASE_URL) -SQLModel.metadata.create_all(engine) \ No newline at end of file + +def create_db_and_tables(): + SQLModel.metadata.create_all(engine) \ No newline at end of file