d5279b124f
Storage Persistence Guard / storage-persistence-audit (push) Has been cancelled
Client Quality Gates / Shared client and Web (push) Has been cancelled
Client Quality Gates / macOS Desktop (push) Has been cancelled
Client Quality Gates / Shared client and Web (pull_request) Has been cancelled
Client Quality Gates / macOS Desktop (pull_request) Has been cancelled
Storage Persistence Guard / storage-persistence-audit (pull_request) Has been cancelled
39 lines
2.1 KiB
Python
39 lines
2.1 KiB
Python
from __future__ import annotations
|
|
from typing import Optional
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Index, String, Text, func
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
__table_args__ = (
|
|
Index("ix_audit_logs_entity_at", "entity_type", "entity_id", "created_at"),
|
|
Index("ix_audit_logs_operator_created", "operator_id", "created_at"),
|
|
Index("ix_audit_logs_client_ip_created", "client_ip", "created_at"),
|
|
Index("ix_audit_logs_client_source_created", "client_type", "created_at"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
study_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("studies.id"), nullable=True)
|
|
entity_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
entity_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), nullable=True)
|
|
action: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
detail: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
operator_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
|
operator_role: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
client_ip: Mapped[Optional[str]] = mapped_column(String(45), nullable=True)
|
|
user_agent: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
|
|
client_type: Mapped[Optional[str]] = mapped_column(String(16), nullable=True)
|
|
client_version: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
|
|
client_platform: Mapped[Optional[str]] = mapped_column(String(16), nullable=True)
|
|
build_channel: Mapped[Optional[str]] = mapped_column(String(16), nullable=True)
|
|
build_commit: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
|