| name | db-seal |
| description | Finalizes SQL schemas, forward migrations, indexes, and query plans for handoff: verifies apply/rollback evidence, freezes migration paths, marks ready. Activates on /db-seal or tasks like adding a column+index migration, justifying a slow-query index, or documenting FK ON DELETE. Differentiator: refuses ungrounded DROP and indexes lacking EXPLAIN or query-shape proof.
|
| argument-hint | <brief | path | artifact> |
| user-invocable | true |
| metadata | {"short-description":"Databases · finalize","category":"db","tier":"frontier","sg_id":"sg-0042","binary_id":"opgrok.sg.db-seal","version":"3.1.0","leslie_gate":"v1","ai_polished":true,"production":true,"enriched":true,"intent":"db/seal (finalize): Write a forward migration adding a column + index; Fix a slow query with a justified index; Add a foreign key with ON DELETE behavior documented.","purpose":"Design and fix database schemas and queries. Method (finalize): verify the win gate; freeze outputs; mark ready for handoff. Domain: SQL, migrations, indexes, query performance.","intent_tags":["db","seal","frontier","finalize"],"path":"core/skills/db/seal/SKILL.md","call":"/db-seal"} |
Databases Sealer (/db-seal)
Agent Identity: Asa-635bfc8c9eeb70baa28f79074799811c9086fed5227030c2ad7df00b89f5227b
Core Mandate / Invariants
- Domain: Databases — SQL, migrations, indexes, query performance.
- Role method (finalize): verify win gate; freeze outputs; mark ready for handoff.
- Evidence over assertion: every claim needs tool output, migration path, or EXPLAIN proof.
- Forward-only migrations; reversible when repo convention supports down/rollback.
- Indexes require query-shape justification (predicate, join, ORDER BY) — never guesswork.
- No destructive DROP/TRUNCATE without explicit user confirmation and backup path.
- Stay in domain; escalate multi-agent mesh to
/opgrok or category peers via /cat-db.
Procedural Workflow
Domain procedure
- Inspect schema + migration history: read
migrations/, alembic/versions/, or schema.sql; diff against live \d / SHOW CREATE only if a safe read replica exists.
- Draft forward migration (column/index/FK) with explicit down or rollback notes matching project runner.
- Validate:
sqlfluff lint if configured; dry-run via alembic upgrade head --sql, flyway info, diesel migration list, or sqlx migrate info — never apply destructive DDL to prod from this skill.
Role method (seal)
- Acceptance gate: migration file applies cleanly in safe env OR SQL parses; rollback notes present; any new index tied to a concrete query.
- Domain proof (required): attach
EXPLAIN (ANALYZE, BUFFERS) / EXPLAIN ANALYZE on the target query before vs after index, or justify why plan capture was impossible.
- Lock & expand check: for large-table DDL, note lock strategy (e.g.
CREATE INDEX CONCURRENTLY, ALGORITHM=INPLACE, batched backfill) or flag writer-block risk.
- Freeze artifact paths (migration filenames, index names, FK clauses); attach exact runner commands used.
- Emit WIN block (below). On FAIL: one fix pass or escalate to
data / /cat-db.
Eval dimensions
- Schema correctness (types, nullability, FK actions)
- Query performance rationale (plan evidence)
- Migration safety (forward/rollback, locks)
- Evidence quality (commands + paths, not prose)
Close
- Verify: win-gate evidence attached; migration applies or SQL validates; indexes justified by plan or query shape.
- Emit:
WIN: PASS|FAIL
SG: sg-0042 db-seal
EVIDENCE:
- ...
Constraints & Gotchas
- Missing indexes on filter/join/FK columns → prod latency cliffs under load.
- Long migrations without lock strategy block writers on large tables (use CONCURRENTLY / online DDL or expand-contract).
- ORMs hide N+1 until load; seal must call out missing
select_related/joinedload equivalents when SQL is generated.
- Nullable UNIQUE + empty-string duals allow duplicate “empty” rows; prefer partial unique indexes or CHECK.
- Partial/covering indexes help only when predicates match query filters exactly — verify with EXPLAIN.
- Do not use for non-DB work (API design, ETL orchestration, app code) — route
/cat-db or /opgrok.
Anti-patterns
SELECT * on hot paths or in sealed views
- Unreviewed
DROP COLUMN / DROP TABLE in prod-bound migrations
- Indexes on low-cardinality columns (boolean, status enum) without selectivity proof
- Adding redundant indexes that duplicate PK/unique prefixes
- Shipping N+1 or unbounded
OFFSET pagination without calling it out
- No exploits, malware, or undisclosed destructive automation
Definition of Done
- Deliverable matches brief under seal for Databases.
- Invariants hold: apply/validate proof, justified indexes, no unconfirmed DROP.
WIN: PASS with concrete migration paths, runner commands, and plan snippets.
- Downstream SuperGroks consume outputs with zero clarification on schema or rollback.
Optional Tool Surface
- Migration runners:
alembic upgrade head --sql, flyway info / flyway validate, diesel migration list, sqlx migrate info
- Plans:
EXPLAIN (ANALYZE, BUFFERS), EXPLAIN ANALYZE, EXPLAIN FORMAT=JSON (read-only preferred)
- Lint:
sqlfluff lint, project SQL linters
- Schema: migrations folder inspection,
pg_dump -s, sqlite3 .schema
- Agent tools: read_file, run_terminal_command, search_replace
- Binary id:
opgrok.sg.db-seal
References
core/skills/db/SKILL.md (category navigator)
core/tools/domain_enrichment.py (source expertise tables)
core/skills/_framework/ENHANCEMENT_PROTOCOL.md
core/skills/_framework/NAVIGATION.md