mirror of
https://github.com/zvx-echo6/central.git
synced 2026-08-26 09:21:36 +00:00
Adds a `kind` TEXT column to `config.adapters` (migration 043) so one adapter
class can later back many operator-created instances. Every built-in adapter
row is back-filled with `kind = name`, keeping all 23 adapters working
unchanged.
- Migration 043: ADD COLUMN IF NOT EXISTS kind, back-fill, SET NOT NULL.
- AdapterConfig gains `kind: str | None` with a model_validator that falls
back to `name` when the column is NULL/absent (pre-043 rows).
- config_store.get_adapter / list_adapters: add `kind` to SELECT.
- supervisor._create_adapter AND _start_adapter (api-key precondition):
resolve the class by config.kind (class key) not config.name (instance key);
runtime state keying stays on config.name.
- routes.py GET/POST /adapters/{name} and adapters_list: add `kind` to SELECT,
resolve the adapter class by row["kind"].
- adapter_discovery.py: comment clarifying .name is the kind (class identity).
- Out of scope, left as-is (built-ins only, name==kind): setup wizard paths in
routes.py (~750/~891/~1109) and gui/__init__.py.
- Tests: 17 new pure-unit tests (migration SQL shape, AdapterConfig back-compat,
_create_adapter + _start_adapter kind dispatch). Existing test mock rows
updated to include the `kind` field.
Co-authored-by: Ubuntu <zvx@cortex.echo6.co>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
1.3 KiB
SQL
25 lines
1.3 KiB
SQL
-- Migration 043: decouple adapter class-identity (kind) from instance-identity (name)
|
|
--
|
|
-- Until now config.adapters.name served two roles:
|
|
-- 1. Instance primary key — the unique name used in runtime state, logs, dedup
|
|
-- tables, NATS subjects, etc.
|
|
-- 2. Registry key — the key used to look up the adapter class in the
|
|
-- supervisor's in-memory registry (discover_adapters returns {class.name: cls}).
|
|
--
|
|
-- These roles must be split so that one adapter class can later back many
|
|
-- operator-created instances (e.g. a generic HTTP adapter). The new `kind`
|
|
-- column holds the class identity (registry key), while `name` remains the
|
|
-- unique instance identifier. All built-in adapters have name == kind, so
|
|
-- every existing row is back-filled with kind = name and behaviour is unchanged.
|
|
--
|
|
-- Idempotent: ADD COLUMN IF NOT EXISTS is safe on re-run.
|
|
-- No DEFAULT is set — future INSERT paths must always supply kind explicitly.
|
|
|
|
ALTER TABLE config.adapters ADD COLUMN IF NOT EXISTS kind TEXT;
|
|
|
|
-- Back-fill: existing rows get kind = name (class identity == instance identity
|
|
-- for all 23 built-in adapters shipped before v0.15.0).
|
|
UPDATE config.adapters SET kind = name WHERE kind IS NULL;
|
|
|
|
-- Enforce non-null going forward.
|
|
ALTER TABLE config.adapters ALTER COLUMN kind SET NOT NULL;
|