Files
Metamorph/backend/app/models/setting.py

38 lines
1.4 KiB
Python
Raw Normal View History

2026-05-11 06:05:27 +02:00
"""Platform settings (key/value JSONB) and admin-defined detection levels."""
from __future__ import annotations
from typing import Any
from sqlalchemy import Integer, String, Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
from app.db.mixins import TimestampMixin, UuidPkMixin
class Setting(Base, TimestampMixin):
__tablename__ = "settings"
key: Mapped[str] = mapped_column(String(80), primary_key=True)
value: Mapped[Any] = mapped_column(JSONB, nullable=False)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
class DetectionLevel(Base, UuidPkMixin, TimestampMixin):
"""Custom taxonomy admin can edit (cf. spec §F6).
Pre-seeded with detected_blocked / detected_alert / logged_only / not_detected.
"""
__tablename__ = "detection_levels"
key: Mapped[str] = mapped_column(String(40), unique=True, nullable=False)
label_fr: Mapped[str] = mapped_column(String(80), nullable=False)
label_en: Mapped[str] = mapped_column(String(80), nullable=False)
color_token: Mapped[str] = mapped_column(String(16), nullable=False)
position: Mapped[int] = mapped_column(Integer, nullable=False)
is_default: Mapped[bool] = mapped_column(default=False, nullable=False)
is_system: Mapped[bool] = mapped_column(default=False, nullable=False)