El Enum guardaba el nombre del miembro (ANALISTA); ahora guarda el valor (analista), igual que declara la migración 0001, que no cambia.
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
"""`usuario`: los tres usuarios demo (analista, oficial, auditor) con hash de contraseña."""
|
|
|
|
import enum
|
|
|
|
from sqlalchemy import Enum, String, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models import Base, ColumnasBaseMixin, TenantMixin
|
|
|
|
|
|
class Rol(enum.StrEnum):
|
|
ANALISTA = "analista"
|
|
OFICIAL = "oficial"
|
|
AUDITOR = "auditor"
|
|
|
|
|
|
class Usuario(ColumnasBaseMixin, TenantMixin, Base):
|
|
__tablename__ = "usuario"
|
|
__table_args__ = (UniqueConstraint("tenant_id", "usuario", name="uq_usuario_tenant_usuario"),)
|
|
|
|
usuario: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
rol: Mapped[Rol] = mapped_column(
|
|
# Se persiste el valor (`analista`), no el nombre del miembro (`ANALISTA`).
|
|
Enum(
|
|
Rol,
|
|
name="rol",
|
|
native_enum=False,
|
|
length=20,
|
|
values_callable=lambda rol: [miembro.value for miembro in rol],
|
|
),
|
|
nullable=False,
|
|
)
|
|
hash: Mapped[str] = mapped_column(String(255), nullable=False)
|