Files
microfish/backend/app/models/settings.py
Kunthawat Greethong e572bc910f fix: boolean server_default must be 'false' not '0' for Postgres
PostgreSQL rejects BOOLEAN DEFAULT 0 (DatatypeMismatch: column ... is of type
boolean but default expression is of type integer). Migration 0008
(platform_settings.active) crashed the alembic upgrade run by the entrypoint,
which in turn crash-looped the worker. Migration 0011 (password_reset_tokens.
used) had the same latent bug and would have failed next.

Change the Boolean server_default from text('0') to text('false') in both
migrations and both ORM models so the DDL is valid on both PostgreSQL
(production) and SQLite (local/tests).

Verified: full 0001->0011 chain runs on fresh SQLite; alembic check reports no
drift; backend suite 201 passed.
2026-08-31 22:21:53 +07:00

43 lines
1.4 KiB
Python

"""Durable, versioned platform settings (LLM provider etc.) with redacted secrets."""
from __future__ import annotations
from datetime import datetime, timezone
from uuid import uuid4
from sqlalchemy import Boolean, DateTime, ForeignKey, JSON, String, func, text
from sqlalchemy.orm import Mapped, mapped_column
from ..db import Base
def _utc_now() -> datetime:
return datetime.now(timezone.utc)
class PlatformSettings(Base):
"""A versioned snapshot of platform LLM settings.
Public/non-secret settings live in ``settings`` (JSON). The API key must be
stored encrypted (as ``secret_ref``), never as plaintext in ``settings``.
``active`` marks the current effective version.
"""
__tablename__ = "platform_settings"
id: Mapped[str] = mapped_column(
String(64), primary_key=True, default=lambda: f"ps_{uuid4().hex}"
)
version: Mapped[str] = mapped_column(String(64), nullable=False, unique=True)
settings: Mapped[dict | None] = mapped_column(JSON, nullable=True)
secret_ref: Mapped[str | None] = mapped_column(String(512), nullable=True)
updated_by_user_id: Mapped[str | None] = mapped_column(
String(64), nullable=True
)
active: Mapped[bool] = mapped_column(
Boolean, nullable=False, default=False, server_default=text("false")
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, default=_utc_now, server_default=func.now()
)