fix: UserRole enum case mismatch with PostgreSQL (OWNER→owner)

This commit is contained in:
enzo
2026-07-22 18:06:17 +08:00
parent eaf13e5f51
commit ff813824fa
2 changed files with 6 additions and 6 deletions
+4 -4
View File
@@ -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)
+2 -2
View File
@@ -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(