cockroachdb-app-patterns

cockroachdb-app-patterns is a cursor rule for Cursor from cockroachdb/cursor-plugin. It costs 0 tokens per session (6,353 once invoked), scanned A, original, Apache-2.0.

A set of coding rules for building applications that use CockroachDB, a distributed SQL database. It covers transactions, database connections, schemas, online changes, batching, and multi-region setups.

In plain words
What is it for?
Use it when writing or reviewing application code that reads from or writes to CockroachDB, including database models, migrations, connection pools, and transaction handling.
Why use it?
It helps prevent errors caused by concurrent transactions, dropped connections, unsafe schema changes, and incorrect database settings.

Cursor rule for Cursor ✓ vendor

Written for Cursor: a Cursor rule (.mdc). Also seen: positional $N argument.

Good fit Use it when writing or reviewing application code that reads from or writes to CockroachDB, including database models, migrations, connection pools, and transaction handling.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns
About the project

CockroachDB Plugin for Cursor connects the Cursor coding agent to CockroachDB clusters for database work such as exploring schemas, writing SQL, debugging queries, and managing distributed clusters. It supports self-hosted and CockroachDB Cloud connections, and its catalogue add-ons provide database-focused agents, skills, rules, and instructions.

cockroachdb/cursor-plugin · 2 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/cockroachdb/cursor-plugin

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cockroachdb-app-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns/github.svg)](https://agentmods.dev/rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns)
Your own site
<a href="https://agentmods.dev/rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns"><img src="https://agentmods.dev/badge/rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cockroachdb-app-patterns

Your own site · 80×15
<a href="https://agentmods.dev/rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns"><img src="https://agentmods.dev/badge/rules/cockroachdb/cursor-plugin/cockroachdb-app-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 6,353 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.06353
Opus 5.5 $0.00000 $0.02541
Sonnet 5.5 $0.00000 $0.01271
Haiku 4.5 $0.00000 $0.00635

Measured 7d ago against content hash b40adb72a1e3, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cockroachdb-app-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/cockroachdb-app-patterns.mdc · 714 lines

How it starts

The opening of the file, as written. The whole thing — 714 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CockroachDB Application Patterns

These rules encode production-tested patterns from cockroachdb-best-practices-demo and cockroachdb-jdbc-wrapper. Follow them strictly when generating code that interacts with CockroachDB.


1. Transaction Retry Logic (MANDATORY)

CockroachDB defaults to SERIALIZABLE isolation — the strongest level. This means any two concurrent transactions touching the same rows may produce a SQLSTATE 40001 (serialization failure). Applications MUST implement retry logic.

Retryable Error Codes

SQLSTATE Meaning Action
40001 Serialization failure (transaction conflict) ALWAYS retry the entire transaction
08001 Unable to establish connection Retry with backoff
08003 Connection does not exist Retry with new connection
08004 Connection rejected by server Retry with backoff
08006 Connection failure during transaction Retry with new connection
08007 Transaction resolution unknown Retry with new connection
08S01 Communication link failure Retry with new connection
57P01 Admin shutdown (node drain/restart) Retry with backoff

Retry Strategy

  • Use exponential backoff with jitter (not fixed delays)
  • Recommended: base 200ms, multiplier 2×, jitter factor 0.5
  • Max attempts: 3–5 for interactive, 5–10 for background/batch
  • Retry the ENTIRE transaction — not just the failed statement

⛔ ANTI-PATTERN: Savepoint-Based Retry

// ❌ WRONG — This does NOT work with CockroachDB
conn.setAutoCommit(false);
Savepoint sp = conn.setSavepoint("cockroach_restart");
try {
    // ... SQL operations ...
    conn.commit();
} catch (SQLException e) {
    if ("40001".equals(e.getSQLState())) {
        conn.rollback(sp);  // ❌ CockroachDB aborts the ENTIRE txn on 40001
        // retrying here is USELESS — the transaction is dead
    }
}

Read the full file on GitHub · 714 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago Changed b40adb72a1e3
  2. 1mo ago First seen · 714 lines · 0 tokens per session scan A 2358f773451f

Subscribe to this mod's changes

cockroachdb-app-patterns is a cursor rule published in the GitHub repository cockroachdb/cursor-plugin (2 stars, last pushed 8d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 6,353 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.