schema-sync-agent-assisted
Four-layer schema sync procedure for the Ghost Contributors NL2SQL system after a database migration. Covers YAML contract, ChromaDB RAG chunks, NL2SQL prompt, and RAG prompt with a step-by-step repair sequence.
- License 许可
- Apache-2.0
- 最近更新
- 2026-04-18
- Stars
- ★ 9
- Forks
- 2
01 前言 Front Matter
- name
- schema-sync-agent-assisted
- description
- Four-layer schema sync procedure for the Ghost Contributors NL2SQL system after a database migration. Covers YAML contract, ChromaDB RAG chunks, NL2SQL prompt, and RAG prompt with a step-by-step repair sequence.
02 资源文件 1
- 参考文档README.md785 B
03 SKILL.md 正文
Schema Sync — Agent Assisted
Context
This system has four layers that break simultaneously when the database schema changes:
| Layer | File / System | What breaks |
|---|---|---|
| YAML contract | agentic_system/schema/github_events.yaml |
Contract no longer matches live DB |
| NL2SQL prompt | agentic_system/agents_core/nl2sql/prompts/system.md |
Agent generates SQL with old predicates → 0 rows, no error |
| RAG prompt | agentic_system/agents_core/rag/prompts/system.md |
Agent describes wrong field semantics to the user |
| ChromaDB chunks | schema_docs, qa_examples collections |
RAG retrieves stale context with wrong field names |
Repair procedure
Step 1 — Introspect live schema
Query ClickHouse to see what the database actually has:
SELECT name, type FROM system.columns WHERE table = 'github_events' ORDER BY position
Use connection settings from agentic_system/config.py (host, port, user, password, database).
Step 2 — Diff against YAML contract
Load agentic_system/schema/github_events.yaml and compare column names and types.
Identify: removed columns, added columns, type changes.
Step 3 — Patch YAML contract
Update agentic_system/schema/github_events.yaml:
- Add entries for new columns with correct type and a clear post-migration description.
- Update the type field for any column whose type changed.
- Update descriptions for migration-sensitive columns (especially merge-related fields).
Step 4 — Patch agent prompts
In both system.md prompt files:
- Replace old field name references with new names.
- Replace old SQL predicates (e.g.
field = 1) with new equivalents (e.g.field IS NOT NULL). - Update any type annotations in the schema table within the prompt.
- Update state labels (
pre-migration→post-migration).
Step 5 — Patch ChromaDB chunks
Connect to ChromaDB at http://localhost:8000 (settings from agentic_system/config.py).
For each collection (schema_docs, qa_examples):
- Get all items:
POST /api/v2/tenants/default_tenant/databases/default_database/collections/{id}/getwith{"include": ["documents", "metadatas"]} - Find items where
metadata.stale == True. - Apply the same text replacements to the document content.
- Re-embed using the deterministic hash function (64 dimensions, same algorithm as
db/vectordb/init/seed_vectors.py). - Upsert back:
POST .../upsertwith updated documents, embeddings, and metadata (stale: false,schema_state: post_migration_synced).
Step 6 — Validate
uv run python scripts/validate_schema.py
Expected: No drift — live schema matches YAML contract exactly.
Also verify neither prompt file contains the old field predicate syntax.
Rollback
To restore the pre-sync state: revert the YAML and prompt file changes, then run make seed-vectors to restore ChromaDB chunks from source.
04 同仓库更多 Skills
backlog-task-creator
Create or update `backlog/<TASK-ID>.md` task files for this repo using the established traceability format. Use when asked to add backlog task documents, standardize task scope and status, or derive task files from `PRODUCT_BACKLOG.md`.
backlog-board-status
Fast status check for backlog tasks using `scripts/backlog_board.py` and `backlog/board.md`. Use when you need a compact view of task id, epic, status, and short description across sessions.
schema-sync-fully-guided
Complete schema drift repair for the Ghost Contributors NL2SQL system. Patches all four layers (YAML contract, ChromaDB RAG chunks, NL2SQL prompt, RAG prompt) using validated tooling. Includes dry-run preview, step-by-step fallback, validation, and rollback.
schema-sync-structured
Fix an agentic NL2SQL system after a database schema change. Inspect the schema contract, agent prompts, and vector database chunks for stale field references and update them.
schema-sync-naive
The database schema changed and the agent is returning wrong answers. Fix it.