Files
xinmi/migrations/versioned/000052_models_managed_by.up.sql
T
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

38 lines
1.8 KiB
SQL

-- Migration: 000052_models_managed_by
-- Add a `managed_by` column to `models` so the YAML built-in models loader can
-- own a slice of the table without disturbing rows created via the UI/API or
-- seeded by hand-written SQL.
--
-- Background:
-- * 000051-era PR #1453 introduced config/builtin_models.yaml as a
-- declarative source of truth for built-in models. The first version
-- could add/update rows but had no way to remove them: deleting an entry
-- from YAML left the corresponding row in `models`, breaking the
-- "declarative" contract and forcing operators back into ad-hoc SQL.
-- * Indiscriminately deleting `is_builtin=true` rows on each startup is
-- unsafe because some deployments seed built-ins via direct SQL, and
-- those rows must not be touched.
--
-- Solution:
-- * Add `managed_by` (varchar(32), default ''). YAML loader writes "yaml";
-- anything else (UI / API / SQL seed) keeps the empty default.
-- * On every startup the loader UPSERTs YAML entries with managed_by='yaml'
-- and soft-deletes rows where (is_builtin=true AND managed_by='yaml' AND
-- id NOT IN <current YAML id set>). Manual rows are never inspected.
--
-- This migration is idempotent (IF NOT EXISTS) and safe to re-run.
DO $$ BEGIN RAISE NOTICE '[Migration 000052] Adding models.managed_by column'; END $$;
ALTER TABLE models
ADD COLUMN IF NOT EXISTS managed_by VARCHAR(32) NOT NULL DEFAULT '';
-- A partial index on the YAML-managed slice keeps the startup sweep cheap
-- even if the table grows large. Manual rows (managed_by='') are excluded
-- so the index stays small.
CREATE INDEX IF NOT EXISTS idx_models_managed_by_yaml
ON models (managed_by)
WHERE managed_by <> '';
DO $$ BEGIN RAISE NOTICE '[Migration 000052] Done'; END $$;