mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-30 11:50:06 +08:00
* Add endpoints for getting, updating, deleting users by global user ID * Resolve formatting * Include alembic revision script * Updated down_revision to current alembic head Co-authored-by: Andreas Köpf <andreas.koepf@xamla.com>
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from uuid import UUID, uuid4
|
|
|
|
import sqlalchemy as sa
|
|
import sqlalchemy.dialects.postgresql as pg
|
|
from sqlmodel import Field, Index, SQLModel
|
|
|
|
|
|
class User(SQLModel, table=True):
|
|
__tablename__ = "user"
|
|
__table_args__ = (Index("ix_user_username", "api_client_id", "username", "auth_method", unique=True),)
|
|
|
|
id: Optional[UUID] = Field(
|
|
sa_column=sa.Column(
|
|
pg.UUID(as_uuid=True), primary_key=True, default=uuid4, server_default=sa.text("gen_random_uuid()")
|
|
),
|
|
)
|
|
username: str = Field(nullable=False, max_length=128)
|
|
auth_method: str = Field(nullable=False, max_length=128, default="local")
|
|
display_name: str = Field(nullable=False, max_length=256)
|
|
created_date: Optional[datetime] = Field(
|
|
sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp())
|
|
)
|
|
api_client_id: UUID = Field(foreign_key="api_client.id")
|
|
enabled: bool = Field(sa_column=sa.Column(sa.Boolean, nullable=False, server_default=sa.true()))
|
|
notes: str = Field(nullable=False, max_length=1024, default="")
|
|
deleted: bool = Field(sa_column=sa.Column(sa.Boolean, nullable=False, server_default=sa.false()))
|