From ff813824fa643f0d0edd55309dbfc5680ac6341f Mon Sep 17 00:00:00 2001 From: enzo Date: Wed, 22 Jul 2026 18:06:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20UserRole=20enum=20case=20mismatch=20with?= =?UTF-8?q?=20PostgreSQL=20(OWNER=E2=86=92owner)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/models/user.py | 8 ++++---- backend/app/services/auth_service.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/app/models/user.py b/backend/app/models/user.py index 80af843..ad4df12 100644 --- a/backend/app/models/user.py +++ b/backend/app/models/user.py @@ -9,9 +9,9 @@ from app.database import Base class UserRole(str, enum.Enum): - OWNER = "owner" - OPERATOR = "operator" - VIEWER = "viewer" + owner = "owner" + operator = "operator" + viewer = "viewer" class User(Base): @@ -21,7 +21,7 @@ class User(Base): username: Mapped[str] = mapped_column(String(50), unique=True, nullable=False, index=True) email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False) hashed_password: Mapped[str] = mapped_column(String(255), nullable=False) - role: Mapped[UserRole] = mapped_column(SAEnum(UserRole), default=UserRole.VIEWER, nullable=False) + role: Mapped[UserRole] = mapped_column(SAEnum(UserRole), default=UserRole.viewer, nullable=False) is_active: Mapped[bool] = mapped_column(Boolean, default=True) is_approved: Mapped[bool] = mapped_column(Boolean, default=False) login_attempts: Mapped[int] = mapped_column(default=0) diff --git a/backend/app/services/auth_service.py b/backend/app/services/auth_service.py index ed1667b..0cced9c 100644 --- a/backend/app/services/auth_service.py +++ b/backend/app/services/auth_service.py @@ -77,10 +77,10 @@ async def create_user(db: AsyncSession, username: str, email: str, password: str existing_count = len(result.scalars().all()) if existing_count == 0: - role = UserRole.OWNER + role = UserRole.owner is_approved = True else: - role = UserRole.VIEWER + role = UserRole.viewer is_approved = False user = User(