ai-powered-conversational-intelligence

43 — Schema Drift Impact Analysis

Continuous schema-drift detection: compare discovery fingerprints and detect added/removed/renamed columns, type/nullability changes, key/ relationship changes, and relevant view/object changes. Map impact to metrics, semantic definitions, golden questions, dashboards, queries, and recommendations through lineage. Generate actionable reports/alerts; do not silently rewrite production definitions. Support approval-aware remediation and metadata rollback. INSPECT/PLAN/IMPLEMENT/TEST/REVIEW/ FIX/DOCUMENT — one new top-level package (schema_drift/), a new standalone REST surface (api/schema_drift.py, two routes), a new standalone CLI (scripts/run_schema_drift_scan.py), an additive extension to Prompt 35’s existing risk-scoring dict, additive config surface, and a dedicated cross-cutting regression test proving the mission’s own “never silently rewrite production definitions” rule structurally. No existing route, node, prompt, model field, or Settings field changed behavior for any pre-existing caller.

1. Inspection: what already existed vs. the real gap

A deterministic column-level schema diff did not exist anywhere in this codebase. The closest prior art was table-level only: embeddings.schema_indexer’s per-database manifest (.schema_manifest__<db>.json) stores a per-table fingerprint and reports added/removed/changed table names (SchemaDiscoveryDiff, read back via get_last_discovery_diff) — enough to decide which Chroma chunks to re-embed, nowhere near enough to say what changed inside a changed table (a type change vs. a nullability change vs. a key change are all just “changed”).

Everything the mission’s own impact-mapping half needs already existed and was reused verbatim, not reimplemented:

The one genuinely missing piece, confirmed by grep (no existing module persists a full column-level historical schema snapshot): a place to keep “the last schema shape we compared against” between scans. Built as schema_drift.snapshot_store, mirroring embeddings.schema_indexer’s own per-database JSON-file-next-to-the-Chroma-dir convention rather than a new identity-DB table (this is an operational cache, not governed content — the governed artifact a scan produces, the findings themselves, already has a home in Prompt 35’s own table).

2. What was built

No frontend page was built — following the established precedent of Prompts 38–41 (scenario/optimization/predictive/data_quality: engine + REST, UI deferred), not Prompt 42’s own exception. Disclosed in §5, not silently omitted.

3. Authorization, tenant isolation, and “never silently rewrite”

4. Testing

All 53 new tests pass; the full pre-existing backend suite was re-run after this change and remains green (confirmed via a full, unfiltered pytest run in this same session, exit code 0) — this prompt’s own additive edits (config/settings.py, api/main.py, semantic/intelligence/risk.py, frontend/vite.config.ts) introduced no regression. ruff check/black --check/mypy were run against every new/edited production file directly: zero new findings (the four pre-existing mypy errors surfaced while checking this package’s own import graph are in db/schema_introspection.py/identity/repositories /semantic_intelligence.py/identity/repositories /recommendation_governance.py, none of which this prompt touched — confirmed via git diff --stat on each, empty).

5. Known, disclosed limitations

A scheduled-job runner (a real, persisted job/cron concept this codebase has never built — onboarding/’s own “no background worker” limitation, named again here, is the same underlying gap) would turn scripts/run_schema_drift_scan.py’s manual/cron-only posture into a first-class, UI-visible “last scanned at / next scan in” feature, and would be the natural place to also auto-trigger POST /schema-drift/scan right after POST /schema/refresh/ refresh_all_schema_indexes succeeds (today two independent, deliberately decoupled actions). A persisted query-lineage history (named as a known gap in both Prompt 42’s and this prompt’s own limitations) would let impact assessment reach real “dashboards”/”golden questions” rather than only schema+catalog nodes.