Database

From event4u-app/agent-config · View interactive version

Database is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when designing schemas and relations, tuning queries or indexes on any SQL engine, or multi-connection patterns — even when the user just says 'this query is slow'.

How to use this skill

Skill file

database

Grounded corpus (Tier-1 consultation): symptom → index/strategy

decisions come grounded — `node

<skills-root>/corpus-grounding/scripts/ground.mjs search --manifest

<skills-root>/database/data/manifest.json "<symptom>"` returns root

cause, strategy, good-code sketch, anti-pattern, and the verification

probe (EXPLAIN expectation). Corpus:

CODE0; its engine versions and

their date live in CODE0 upstream.

Repeating them here is how this line fell two majors behind.

When to use

Use when designing schemas, optimizing queries, adding indexes, or troubleshooting database performance.

This skill owns relational modeling — invariants, cardinality, keys, junction

tables, index method, enum representation, referential actions. Designing or

extending a schema → CODE0.

Dropping or renaming anything → CODE0 first.

Do NOT use when:

Procedure: Optimize a query

Step 0: Inspect

  1. Read project docs in agents/reference/docs/ for database architecture.
  2. Check config/database.php for connection definitions.
  3. Detect engine: check .env driver and docker-compose.yml.
  4. Detect hosting per environment: a docker-compose.yml service describes

local/dev only; an RDS, Cloud SQL, Azure, PlanetScale or Neon host or

Terraform resource marks production as managed and wins; no production marker

→ production hosting is unknown, never assumed self-hosted.

Managed guardrail: no ALTER SYSTEM, no postgresql.conf / my.cnf

edit, no OS access — server settings go through the provider's parameter

group or control-plane CLI.

Step 1: Diagnose

Run EXPLAIN / EXPLAIN ANALYZE:

EXPLAIN ANALYZE SELECT * FROM projects WHERE customer_id = 42 AND status = 'active';

Check for: full table scans (type=ALL), missing indexes (key=NULL), filesort, temporary tables.

Step 2: Fix

Step 3: Verify

Re-run EXPLAIN and confirm improved plan.

Schema awareness (anti-hallucination)

Never guess table or column names. Verify before writing queries/migrations:

  1. Read migrations — source of truth
  2. Read models — $table, $connection, $fillable, $casts, relationships
  3. Run schema queries — use the project's REPL or a raw introspection query:
  1. Check project docs — agents/reference/docs/ for conventions
  2. Map facts (files only): CODE0

| Trap | Reality |

|---|---|

| Assuming column exists | Check migration/model first |

| Wrong table prefix | Customer tables may have prefixes |

| Wrong connection | api_database vs customer_database — verify |

| Inventing pivot tables | Check if they actually exist |

Dump to the Evidence Report (source-discovery)

When the task touches schema-driven work, this dump is the DB surface of the

CODE0 discipline. Record it to the

gitignored session cache with provenance, framework-neutral (MySQL / Postgres /

SQLite; ORM-agnostic):

relations, and the derived filter/sort/group-ability** — each with

observed_at / source (migration:line or the introspection command).

migrations / models / ORM / app code (including schemaless stores the app

controls — Mongoose / Prisma / Firestore rules) is always resolved locally and

re-read each task. The migration is intended truth, the live DB is actual —

surface any divergence as a drift signal.

"searched, column/table does not exist" after an exhausted search. Positive

structure stays in the session Evidence Report, re-read fresh — never a card.

repo and not app-controlled) is the only DB that may be card-worthy.

Conventions

→ See guideline php/database.md for indexing, transactions, migrations, multi-connection patterns.

Output format

  1. Migration file or query change with EXPLAIN analysis
  2. Index recommendations with rationale

Gotcha

**MySQL and MariaDB share a query-syntax world. They never share a migration

one.** Treat them as one engine for writing a SELECT, and as two engines for

everything that changes a schema or reports on a plan: online-DDL semantics,

lock behavior under ALTER, feature availability, and EXPLAIN output all

diverge. Read the engine and its version from the project before making any

claim in that second group; where the project does not declare one, say the

engine is unknown rather than assuming.

Do NOT

Auto-trigger keywords

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.