Fix 500 error on user creation by updating database paths and handling missing default role
This commit is contained in:
parent
61c5a0945a
commit
b8141097dc
@ -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]
|
||||
|
@ -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}"
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user