Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .agents/skills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A complete skill is a directory with a required `SKILL.md` file and optional bun
| --- | --- | --- |
| [`audit-skill-security`](audit-skill-security/SKILL.md) | Auditing third-party or local skills before installing, updating, or trusting them. | [`references/audit-protocol.md`](audit-skill-security/references/audit-protocol.md) |
| [`codegen-backend`](codegen-backend/SKILL.md) | Production backend code: APIs, services, middleware, workers, persistence, validation, auth, and backend tests. | [`references/`](codegen-backend/references/), [`evals/`](codegen-backend/evals/) |
| [`codegen-database`](codegen-database/SKILL.md) | Database code: schemas, DDL, OLTP SQL, analytics SQL, migrations, indexes, stored procedures, and dialect-specific scripts. | [`references/`](codegen-database/references/), [`evals/`](codegen-database/evals/) |
| [`codegen-frontend`](codegen-frontend/SKILL.md) | Production frontend code: components, routes, client state, forms, styling, accessibility, performance, PWA behavior, and visualization. | [`references/`](codegen-frontend/references/), [`evals/`](codegen-frontend/evals/) |
| [`codegen-test`](codegen-test/SKILL.md) | Automated tests and evals, including E2E, API, integration, performance, AI output, tool-use, RAG, and prompt regression suites. | [`references/`](codegen-test/references/), [`scripts/`](codegen-test/scripts/), [`evals/`](codegen-test/evals/) |
| [`creator-rule`](creator-rule/SKILL.md) | Writing or improving agent rules, instruction files, `AGENTS.md`, `CLAUDE.md`, Cursor rules, Copilot instructions, and `.agents/rules/*.md`. | [`scripts/`](creator-rule/scripts/), [`evals/`](creator-rule/evals/) |
Expand All @@ -21,7 +22,6 @@ A complete skill is a directory with a required `SKILL.md` file and optional bun
| [`review-code`](review-code/SKILL.md) | Reviewing code changes, diffs, pull requests, branches, or patches for correctness, regressions, security, performance, and test gaps. | [`references/`](review-code/references/), [`evals/`](review-code/evals/) |
| [`writer-prd`](writer-prd/SKILL.md) | Product requirements, product briefs, feature requirements, product scope, and launch requirements. | [`references/`](writer-prd/references/), [`evals/`](writer-prd/evals/) |
| [`writer-spec`](writer-spec/SKILL.md) | Technical specs, design docs, functional and non-functional requirements, data contracts, UI specs, release specs, and handoff docs. | [`references/`](writer-spec/references/), [`evals/`](writer-spec/evals/) |
| [`writer-sql`](writer-sql/SKILL.md) | Database schemas, SQL queries, dialect guidance, normalization, indexing, optimization, and troubleshooting. | [`references/`](writer-sql/references/), [`evals/`](writer-sql/evals/) |
| [`writer-tech-docs`](writer-tech-docs/SKILL.md) | READMEs, API docs, endpoint references, routine and on-call runbooks, changelogs, and release notes. | [`references/`](writer-tech-docs/references/), [`evals/`](writer-tech-docs/evals/) |
| [`writer-user-story`](writer-user-story/SKILL.md) | User stories, acceptance criteria, developer tasks, tickets, story points, and sprint planning breakdowns. | [`references/`](writer-user-story/references/), [`evals/`](writer-user-story/evals/) |

Expand All @@ -41,13 +41,13 @@ Use [`creator-skill`](creator-skill/SKILL.md) to create, revise, package, or eva

```bash
cd .agents/skills/creator-skill
python3 -m scripts.package_skill ../writer-sql /tmp/skills-dist
python3 -m scripts.package_skill ../codegen-database /tmp/skills-dist
```

Use this validation command when changing an existing skill:

```bash
python3 .agents/skills/creator-skill/scripts/quick_validate.py .agents/skills/writer-sql
python3 .agents/skills/creator-skill/scripts/quick_validate.py .agents/skills/codegen-database
```

The key rule is simple: keep `SKILL.md` and any files it references together. If a skill says to read `references/postgres.md`, that file must remain available relative to the skill folder. Tiny rule, large consequences. Filesystems enjoy pettiness.
88 changes: 88 additions & 0 deletions .agents/skills/codegen-database/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: codegen-database
description: >
Generate or modify database code: schemas, DDL, SQL queries, migrations, analytics SQL,
indexes, stored procedures, and dialect-specific database scripts.
author: Oleg Shulyakov
license: MIT
version: 1.0.0
---

# codegen-database

Generate production-ready database code for schemas, DDL, OLTP queries, analytics SQL, migrations, indexes, stored procedures, and dialect-specific scripts. Use this as a router: classify the database artifact first, detect the dialect from context or repository evidence, then read only the relevant references.

## Variant Detection

**Route from artifact type before choosing syntax details.**

- **Schema design:** Requests for entities, tables, relationships, normalization, constraints, ERD-to-DDL, or "what tables do I need" route to `references/schema-design.md`.
- **Migrations:** Requests for up/down migrations, Flyway, Liquibase, Rails/ActiveRecord migrations, Alembic, Prisma migrations, rollback, data backfills, or deployment-safe DDL route to `references/migration.md`.
- **OLTP SQL:** Requests for queries, DML, views, indexes, transactions, upserts, stored procedures, or query optimization route to `references/common.md`, then the dialect reference.
- **Analytics SQL:** Requests for warehouses, metrics, cohorts, funnels, retention, partitioned fact tables, dbt-like transformations, BigQuery, Snowflake, or ClickHouse route to `references/analytics.md`, then any matching warehouse reference.
- **Adjacent skills:** Use `report-db-health` for database health findings from existing telemetry. Use `strategy-backup` for backup and recovery policy. Use `writer-spec` for data contracts when the output is prose rather than executable database code.
- **Ambiguity:** If the artifact type or database remains genuinely ambiguous after inspecting context, ask one short question naming the likely choices.

## Dialect Routing

**Choose the database from explicit signals, then repository evidence, then ask only if the choice changes the code.**

| Signal | Reference |
| --- | --- |
| PostgreSQL, Postgres, `JSONB`, `TIMESTAMPTZ`, `ON CONFLICT`, `pg`, `psql` | `references/postgres.md` |
| MySQL, MariaDB, `AUTO_INCREMENT`, `ON DUPLICATE KEY`, `mysql2` | `references/mysql.md` |
| SQL Server, MSSQL, T-SQL, `pyodbc`, `OFFSET-FETCH`, `MERGE` | `references/mssql.md` |
| SQLite, embedded/mobile/local database, FTS5, WAL mode | `references/sqlite.md` |
| Oracle, PL/SQL, sequences, `DUAL`, Oracle hints | `references/oracle.md` |
| BigQuery, GoogleSQL, ARRAY/STRUCT, partitioned warehouse tables | `references/bigquery.md` |
| Snowflake, VARIANT, streams/tasks, clustering, time travel | `references/snowflake.md` |
| ClickHouse, MergeTree, materialized views, sparse indexes | `references/clickhouse.md` |
| CockroachDB, distributed SQL, follower reads, regional tables | `references/cockroachdb.md` |

If the user asks for portable SQL, use `references/common.md` and avoid dialect-specific syntax unless you clearly mark alternatives.

## Working Rules

**Database code must be executable, reversible when applicable, and honest about assumptions.**

- **Inspect first:** Read existing migrations, schema files, ORM models, query builders, naming conventions, fixtures, and migration tooling before editing repository files.
- **Prefer structural guarantees:** Encode business rules with constraints, foreign keys, uniqueness, checks, generated columns, and transaction boundaries before relying on application-only enforcement.
- **Keep migrations safe:** Make destructive DDL explicit, separate schema changes from risky data rewrites when needed, and include rollback or forward-fix guidance when true rollback is unsafe.
- **Use parameters:** Never generate SQL that interpolates user input into executable statements. Use the placeholder style for the target dialect or framework.
- **Index deliberately:** Tie each recommended index to a query, constraint, or access pattern. Avoid adding write-costly indexes without a reason.
- **Handle concurrency:** Use transactions, locks, isolation levels, uniqueness, idempotency keys, or retry notes when the database operation can race.
- **Respect dialect limits:** Do not mix syntax across engines. If the dialect is unknown and syntax materially differs, ask once instead of producing decorative nonsense in SQL clothing.
- **Verify locally:** Run the narrowest relevant migration check, SQL parser, formatter, test, or application test available. If no database is available, state what was reviewed statically.

## Implementation Flow

**Move from existing schema to minimal database change to verification.**

1. Identify artifact type and dialect, then read the selected artifact reference and dialect reference.
2. Inspect the closest existing schema, migration, query, model, and tests.
3. Plan the minimal database surface: tables, columns, constraints, indexes, migrations, queries, and tests or fixtures.
4. Edit using project naming and migration conventions.
5. Add or update focused tests, fixtures, or migration assertions when the repository supports them.
6. Run focused verification and fix regressions within scope.

## Output Format

**Return runnable database code plus the operational context needed to use it.**

When editing a repository, finish with changed files, commands run, and verification status.

When drafting code only, include:

```text
Assumptions:
- ...

SQL / Migration:
- ...

Performance:
- ...

Rollback / Safety:
- ...
```
Loading
Loading