feat(db): all domain models, initial Alembic migration (32 tables), seed script (8 districts, 89 regions, roles)
This commit is contained in:
1 parent
71460ab56a
commit
4a610ba94a
19 files changed
+1290
-2
No files matched your search
@@ -0,0 +1,49 @@
|
||||
"""Модели аудита и AI-ассистента."""
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, JSON, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.db.session import Base
|
||||
from app.models.enums import ActorType
|
||||
from app.models.types import enum_col
|
||||
|
||||
|
||||
class AuditLog(Base):
|
||||
__tablename__ = "audit_log"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
actor_user_id: Mapped[int | None] = mapped_column(ForeignKey("users.id"))
|
||||
actor_type: Mapped[ActorType] = mapped_column(enum_col(ActorType))
|
||||
action: Mapped[str] = mapped_column(String(100))
|
||||
entity_type: Mapped[str | None] = mapped_column(String(100))
|
||||
entity_id: Mapped[str | None] = mapped_column(String(100))
|
||||
payload: Mapped[dict | None] = mapped_column(JSON)
|
||||
ip: Mapped[str | None] = mapped_column(String(64))
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class AssistantConfig(Base):
|
||||
__tablename__ = "assistant_configs"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
owner_user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), unique=True)
|
||||
enabled: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
permissions: Mapped[dict | None] = mapped_column(JSON)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
|
||||
class AssistantAction(Base):
|
||||
__tablename__ = "assistant_actions"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
owner_user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
||||
action: Mapped[str] = mapped_column(String(100))
|
||||
entity_type: Mapped[str | None] = mapped_column(String(100))
|
||||
entity_id: Mapped[str | None] = mapped_column(String(100))
|
||||
payload: Mapped[dict | None] = mapped_column(JSON)
|
||||
status: Mapped[str] = mapped_column(String(20), default="ok")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
Reference in new issue
Block a user