Persona — core.identidad.mae_personas¶
Maestro de personas naturales (cédula) del núcleo. Hereda de mae_entidades (patrón party).
from datetime import datetime, date
from typing import Optional
import uuid
from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Date,
DateTime,
ForeignKey,
Identity,
Index,
Integer,
SmallInteger,
String,
Text,
UniqueConstraint,
text,
)
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class MaePersona(MaeEntidad):
__tablename__ = 'mae_personas'
__table_args__ = (
UniqueConstraint('identificacion', name='uq_mae_personas_identificacion'),
{"schema": 'core.identidad'},
)
__mapper_args__ = {"polymorphic_identity": "PERSONA_NATURAL"}
id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
ForeignKey("core.identidad.mae_entidades.id"),
primary_key=True,
comment='Mismo id de mae_entidades (herencia de tabla)',
)
tipo_identificacion_id: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True),
ForeignKey("cat_tipos_identificacion.id"),
comment='Tipo de identificación',
)
identificacion: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment='Número de identificación',
)
nombres: Mapped[str] = mapped_column(
String(100),
nullable=False,
comment='Nombres de la persona',
)
apellidos: Mapped[str] = mapped_column(
String(100),
nullable=False,
comment='Apellidos de la persona',
)
fecha_nacimiento: Mapped[date | None] = mapped_column(
Date,
comment='Fecha de nacimiento',
)
genero_id: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True),
ForeignKey("cat_generos.id"),
comment='Género de la persona',
)
email: Mapped[str | None] = mapped_column(
String(150),
comment='Correo electrónico',
)
telefono: Mapped[str | None] = mapped_column(
String(20),
comment='Teléfono',
)
direccion: Mapped[str | None] = mapped_column(
String(300),
comment='Dirección',
)
# Auditoría General
is_activo: Mapped[bool] = mapped_column(
Boolean,
nullable=False,
server_default=text("true"),
comment='Estado lógico del registro',
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
server_default=text("now()"),
comment='Fecha de creación',
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
server_default=text("now()"),
comment='Fecha de última actualización',
)
deleted_at: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True),
comment='Fecha de eliminación lógica',
)
created_by: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True),
comment='Usuario creador',
)
updated_by: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True),
comment='Usuario modificador',
)