feat(builtin-models): add managed_by column to models table

Introduce a `managed_by` varchar column on `models` so future declarative
loaders can claim ownership of a subset of rows without disturbing entries
created via the UI/API or seeded by hand-written SQL.

- versioned/000052_models_managed_by.{up,down}.sql add the column with a
  default of '' and a partial index on non-empty values to keep startup
  reconciliation cheap.
- sqlite/000000_init.up.sql is updated in place (the Lite init migration
  is a single file per project convention) so fresh SQLite databases get
  the column from the start.
- Model.ManagedBy mirrors the column. Existing rows default to '' which
  the YAML loader treats as "manually managed, never touch".

Schema half of the YAML-driven built-in-model lifecycle work that follows
up on #1453; the reconciler that uses the column lands in the next commit.
This commit is contained in:
wizardchen
2026-05-26 11:20:13 +08:00
committed by lyingbug
parent d439b3ae07
commit fdc22fd7a5
4 changed files with 52 additions and 0 deletions
+8
View File
@@ -105,6 +105,14 @@ type Model struct {
IsDefault bool `yaml:"is_default" json:"is_default"`
// Whether the model is a builtin model (visible to all tenants)
IsBuiltin bool `yaml:"is_builtin" json:"is_builtin" gorm:"default:false"`
// ManagedBy identifies which subsystem owns this row's lifecycle.
// Empty / "" = manually created (UI / API / hand-written SQL); the YAML
// builtin-models loader leaves these untouched.
// "yaml" = declared in config/builtin_models.yaml; on every startup the
// loader UPSERTs the YAML set and soft-deletes YAML-managed rows whose
// id is no longer present in the file. Future origins (e.g. "helm",
// "operator") can claim their own slice without interfering.
ManagedBy string `yaml:"managed_by" json:"managed_by,omitempty" gorm:"type:varchar(32);default:''"`
// Model status, default: active, possible: downloading, download_failed
Status ModelStatus `yaml:"status" json:"status"`
// Creation time of the model