agentleFS
murillo-consultingmurillo-consulting/cli-skills/cli-forge-data/SKILL.md

cli-forge-data

Skill0 starsChanged 3 months agoMITView on GitHub

Design and implement safe PostgreSQL database changes for Rust/SQLx applications. Use for new schemas, migrations, constraints, indexes, repositories, transaction boundaries, state machines, idempotency, concurrency control, queues, multi-tenancy, soft deletion, ledgers, outbox/inbox, repair jobs, or corrections handed off by cli-audit-data.

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

20 rules. About 0 are common, 12 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read ../shared/data-invariants.md before acting.

    line 32
  2. Very specific:

    Read ../shared/data-invariant-catalog.md when discovering domain rules, and ../shared/postgres-sqlx-patterns.md before writing non-trivial …

    line 33
  3. Distinctive:

    Do not implement in design-only mode.

    line 44
  4. Distinctive:

    Put every write belonging to one business decision in one explicit transaction.

    line 51
  5. Distinctive:

    Never perform network I/O while a PostgreSQL transaction is open.

    line 52
  6. Distinctive:

    Treat zero affected rows as a business result when the command is conditional.

    line 53
  7. Distinctive:

    Use a transactional outbox/inbox protocol for cross-system effects.

    line 56
  8. Distinctive:

    Never edit an already-applied migration silently.

    line 58
  9. Distinctive:

    Never use SQLite or mocks as proof of PostgreSQL concurrency behavior.

    line 61
  10. Distinctive:

    Never claim cross-system exactly-once behavior without a demonstrated protocol.

    line 62
  11. Distinctive:

    Do not accept an invariant enforced only by Rust validation when PostgreSQL can protect it.

    line 94
  12. Distinctive:

    Write concrete A/B interleavings for every read-before-write flow.

    line 98
  13. Very specific:

    Use named NOT NULL, CHECK, UNIQUE, partial unique indexes, foreign keys, composite tenant keys, exclusion constraints, conditional DML, or …

    line 112
  14. Very specific:

    Prefer compile-time checked query!, query_as!, query_scalar!, and query_file!

    line 121
  15. Distinctive:

    Place the transaction boundary at the business use case and pass the same transaction or connection through participating functions.

    line 126
  16. Very specific:

    Verify the exact SQLx Executor/Transaction API against the project's pinned version.

    line 128
  17. Very specific:

    Use the database T0-T4/M0 mapping in ../shared/data-invariants.md.

    line 154
  18. Very specific:

    Run /cli-audit-data after implementation for L1+ changes or whenever this skill was triggered by a database-safety finding.

    line 175
  19. Distinctive:

    every runtime-dependent claim as:

    line 193
  20. Very specific:

    When running under cli-cycle, emit .agents/cli-forge-data.json using ../shared/result-schema.md.

    line 199

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Optimization: Load the shared invariant contract first, then only the PostgreSQL/SQLx references needed by the requested change.

Language rule: Write user-facing decisions and reports in the project's dominant language. Keep SQL, Rust identifiers, SQLSTATE values, and the mandatory uncertainty marker unchanged.

Forge Data — Safe PostgreSQL and SQLx Changes

Design or implement database changes whose safety comes from explicit invariants, PostgreSQL guarantees, short atomic operations, compatible evolution, and reproducible proof.

Read ../shared/data-invariants.md before acting. Read ../gotchas.md before producing output. Read ../shared/data-invariant-catalog.md when discovering domain rules, and ../shared/postgres-sqlx-patterns.md before writing non-trivial SQL.

Modes

ModeTriggerBehavior
DesignUser asks for schema, transaction, migration, or data architectureProduce a database decision and proof plan before code
ImplementationUser asks to build/fix the change or accepts a designEdit migrations/Rust/tests, then execute the relevant gates
Correctioncli-audit-data finding is suppliedPreserve the finding's invariant and close the smallest unsafe gap

Do not implement in design-only mode. In implementation or correction mode, inspect the existing schema and code before editing; never infer the database solely from Rust structs.

Non-negotiable rules

  1. Give every business fact one authoritative owner.
  2. Protect persistent invariants in PostgreSQL whenever a declarative guarantee exists.
  3. Put every write belonging to one business decision in one explicit transaction.
  4. Never perform network I/O while a PostgreSQL transaction is open.
  5. Treat zero affected rows as a business result when the command is conditional.
  6. Give every retryable command an explicit idempotency protocol.
  7. Retry a whole failed transaction, never one middle statement.
  8. Use a transactional outbox/inbox protocol for cross-system effects.
  9. Design migrations for old code, new code, and mixed-version deployment.
  10. Never edit an already-applied migration silently.
  11. Include tenant scope in database keys and references, not only query filters.
  12. Make derived facts reconstructible or provide auditable detection and repair.
  13. Never use SQLite or mocks as proof of PostgreSQL concurrency behavior.
  14. Never claim cross-system exactly-once behavior without a demonstrated protocol.

Workflow

1. Inspect existing truth

Inspect relevant migrations, tables, types, constraints, indexes, triggers, functions, views, RLS, extensions, SQLx queries, transaction boundaries, background jobs, messages, external effects, versions, migration runner, deployment order, and incident history.

Proceed with explicit assumptions when information is missing. Stop before destructive or irreversible work whose semantics cannot be safely inferred.

2. Classify scope and criticality

Choose S/M/L/XL from ../shared/tiering.md for output depth and L0-L3 from ../shared/data-invariants.md for proof depth. State both. Bias scope down and criticality up when uncertain.

3. Write the decision and invariants

Complete the database decision, source-of-truth map, invariant matrix, conservation laws, and state transition tables defined in ../shared/data-invariants.md.

For each invariant choose:

  • a primary PostgreSQL guarantee;
  • defense in depth where useful;
  • an audit query and threshold;
  • a repair or reconstruction path;
  • an executable proof.

Do not accept an invariant enforced only by Rust validation when PostgreSQL can protect it.

4. Break concurrent and failure cases

Write concrete A/B interleavings for every read-before-write flow. Cover duplicate requests, stale writes, lost responses, crash boundaries, retries, old/new binaries, wrong tenant, cancellation, and deadlock or serialization failure.

Prefer, in order:

  1. declarative constraint plus atomic DML;
  2. INSERT ... ON CONFLICT or conditional UPDATE ... RETURNING;
  3. targeted row locking in a short transaction;
  4. SERIALIZABLE with bounded whole-transaction retry;
  5. advisory locking only with a stable key and shared documented protocol.

5. Select PostgreSQL guarantees

Use named NOT NULL, CHECK, UNIQUE, partial unique indexes, foreign keys, composite tenant keys, exclusion constraints, conditional DML, or outbox/inbox as appropriate.

Choose every ON DELETE and ON UPDATE action. Do not claim a row CHECK protects a multi-row invariant. Justify indexes from real access paths and representative volumes. Use triggers only when their central guarantee outweighs hidden complexity and they are observable and tested.

6. Implement with SQLx

Prefer compile-time checked query!, query_as!, query_scalar!, and query_file! variants. Require explicit columns, bound values, allowlisted dynamic identifiers, justified nullability, RETURNING where it removes a second read, zero-row handling, and error mapping by SQLSTATE and named constraint.

Place the transaction boundary at the business use case and pass the same transaction or connection through participating functions. Do not reacquire from the pool inside the use case. Verify the exact SQLx Executor/Transaction API against the project's pinned version.

7. Evolve the schema compatibly

Classify the migration as additive, compatible transformation, backfill, destructive, locking, rewriting, extension-dependent, or version-incompatible.

For non-trivial changes use:

EXPAND -> MIGRATE -> SWITCH -> CONTRACT

Prove old/old, old/new, new/old, new/new, and old+new/new combinations where deployment overlap exists. Analyze locks, rewrite, disk, replication lag, pool impact, batch size, resumability, interruption recovery, and runner transaction behavior. Contract only after telemetry proves old representations and binaries are gone.

8. Build homeostasis

For critical invariants define audit query, frequency, metric, threshold, owner, dry-run repair, audited repair, and replay path. For eventual consistency define nominal and maximum lag, user-visible degraded behavior, retry limit, failed-item storage, and escalation.

9. Implement the proof ladder

Use the database T0-T4/M0 mapping in ../shared/data-invariants.md.

At minimum run the commands supported by the project version:

cargo fmt --check
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo sqlx prepare --workspace --check
cargo test --workspace

For L2+, use synchronized transactions against real PostgreSQL. For L3, add property-based or state-model proof, crash-boundary simulation, full replay, and repair testing. Never report a command as successful unless it ran.

10. Pass the done gate

Apply ../shared/done-gate.md: confirm the decision and baseline before editing, keep the change reversible during implementation, and capture reproducible post-verification. Apply ../shared/determinism.md to fixtures, IDs, clocks, retry schedules, and migration data.

Run /cli-audit-data after implementation for L1+ changes or whenever this skill was triggered by a database-safety finding.

Mandatory output

End with:

  1. scope tier and data criticality;
  2. database decision;
  3. sources of truth and invariant matrix;
  4. conservation laws and state machine;
  5. concurrency and idempotency analysis;
  6. PostgreSQL guarantees;
  7. SQLx implementation notes;
  8. migration compatibility matrix;
  9. proof executed and not executed;
  10. homeostasis and repair;
  11. residual risks and rollback/forward-repair path;
  12. every runtime-dependent claim as:
À PROUVER SUR POSTGRESQL RÉEL — ...

When running under cli-cycle, emit .agents/cli-forge-data.json using ../shared/result-schema.md.

Dynamic handoffs

Condition detectedRecommendWhy
Implementation or migration is ready for an independent safety gate/cli-audit-dataVerify invariants and dangerous interleavings
Contract intent is missing or disagrees with code/cli-audit-driftEstablish semantic ownership
Component architecture or API boundary is unresolved/cli-forge-lldAnchor the database design in the component design
Backup, restore, failover, or incident response is incomplete/cli-forge-resilienceBuild operational proof
Query/index/locking performance is uncertain/cli-forge-perfMeasure rather than speculate
A state machine or data flow needs visualization/cli-forge-schemaGenerate the appropriate Mermaid diagram

Rule: recommend handoffs; do not execute them automatically outside cli-cycle.

Completion criterion

The change is complete only when its laws are explicit, PostgreSQL protects them as far as possible, concurrent and failure executions have concrete answers, old and new versions can coexist safely, proof is reproducible, and remaining drift is observable and repairable.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.