From b8141097dc1cc347eefedcc70c9e4cbf457d8168 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Thu, 15 May 2025 20:23:29 +0000 Subject: [PATCH] Fix 500 error on user creation by updating database paths and handling missing default role --- alembic.ini | 3 ++- app/core/config.py | 2 +- app/services/user.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/alembic.ini b/alembic.ini index cb5aa80..6b48fe2 100644 --- a/alembic.ini +++ b/alembic.ini @@ -36,7 +36,8 @@ script_location = alembic # output_encoding = utf-8 # sqlalchemy.url is now set dynamically in env.py -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +# This URL is a placeholder and will be overridden in env.py +sqlalchemy.url = driver://user:pass@localhost/dbname # Logging configuration [loggers] diff --git a/app/core/config.py b/app/core/config.py index f6f79d0..3b1dfa2 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -19,7 +19,7 @@ class Settings(BaseSettings): BACKEND_CORS_ORIGINS: List[str] = ["*"] # Database settings - DB_DIR: Path = Path("/app") / "storage" / "db" + DB_DIR: Path = Path(__file__).parent.parent.parent / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) DB_PATH: Path = DB_DIR / "db.sqlite" SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_PATH}" diff --git a/app/services/user.py b/app/services/user.py index cb49433..b954834 100644 --- a/app/services/user.py +++ b/app/services/user.py @@ -52,6 +52,17 @@ def create_user(db: Session, user_in: UserCreate) -> User: db_user_role = UserRole(user_id=db_user.id, role_id=default_role.id) db.add(db_user_role) db.commit() + else: + # Create default role if it doesn't exist + default_role = Role(name="user", description="Regular user with limited access") + db.add(default_role) + db.commit() + db.refresh(default_role) + + # Now assign it + db_user_role = UserRole(user_id=db_user.id, role_id=default_role.id) + db.add(db_user_role) + db.commit() return db_user