database

database is a cursor rule for Cursor from kok-o/koko-contextos-agents. It costs 24 tokens per session (1,672 once invoked), scanned A, original, MIT.

Rules for designing and using relational databases, including PostgreSQL, Prisma, and Drizzle. It covers schemas, migrations, indexes, transactions, and slow-query problems.

In plain words
What is it for?
Designing schemas, writing ORM queries, planning migrations, adding indexes, using transactions, and fixing N+1 queries—repeated database queries caused by looping over records.
Why use it?
It helps prevent unsafe database changes, inefficient queries, missing indexes, and inconsistent multi-record updates.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Designing schemas, writing ORM queries, planning migrations, adding indexes, using transactions, and fixing N+1 queries—repeated database queries caused by looping over records.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/kok-o/koko-contextos-agents/database
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/kok-o/koko-contextos-agents

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 database

README.md
[![agentmods](https://agentmods.dev/badge/rules/kok-o/koko-contextos-agents/database/github.svg)](https://agentmods.dev/rules/kok-o/koko-contextos-agents/database)
Your own site
<a href="https://agentmods.dev/rules/kok-o/koko-contextos-agents/database"><img src="https://agentmods.dev/badge/rules/kok-o/koko-contextos-agents/database/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 database

Your own site · 80×15
<a href="https://agentmods.dev/rules/kok-o/koko-contextos-agents/database"><img src="https://agentmods.dev/badge/rules/kok-o/koko-contextos-agents/database.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 24 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,672 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.00024 $0.01672
Opus 5.5 $0.00010 $0.00669
Sonnet 5.5 $0.00005 $0.00334
Haiku 4.5 $0.00002 $0.00167

Measured 1mo ago against content hash 88362f614439, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

database 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 1mo 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.

.cursor/rules/database.mdc · 200 lines

How it starts

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

Skill: database

database

Overview

Relational database design, query optimization, migration safety, connection pooling in serverless environments, and ORM usage across PostgreSQL, Prisma, and Drizzle.

When to Use

Activate for tasks involving database schema design, migrations, indexing, relational models, ORM queries, transactions, or query performance tuning.

Rules & Patterns

Negative Constraints (What NOT to Do)

  1. NEVER do SELECT * in production: Always select explicit columns required by the caller to minimize memory bandwidth and lock footprint.
  2. NEVER run destructive migrations without backward compatibility: Always follow expand-and-contract (Phase 1: add new column as nullable; Phase 2: backfill; Phase 3: make non-nullable & remove old column).
  3. NEVER execute queries in loops (The N+1 Anti-Pattern): Always use batch loading (inArray, DataLoader, or relational include / JOIN).
  4. NEVER leave foreign keys without indexes: In PostgreSQL/MySQL, child foreign key columns must always have an index to prevent table-level locking on cascade deletes.
  5. NEVER perform multi-entity writes without a database transaction: Any operation touching multiple records must use prisma.$transaction or db.transaction.
  6. NEVER open unpooled database connections in Serverless / Edge functions: Serverless scale-outs will instantly exhaust PostgreSQL's max_connections.

Zero-Downtime Migrations (Expand-and-Contract)

When modifying schemas with zero downtime:

  1. Phase 1 (Expand): Add the new column as NULLABLE (or with a default value). Deploy the application code that reads from old column and writes to both old and new.
  2. Phase 2 (Backfill): Run an asynchronous batch migration job in chunks (e.g. 1000 rows at a time) to populate data from old column to new column.
  3. Phase 3 (Contract): Update application code to read and write exclusively from the new column.
  4. Phase 4 (Cleanup): Once traffic is fully shifted, remove the old column and mark the new column as NOT NULL in a separate migration.

Read the full file on GitHub · 200 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. 1mo ago Changed · +52 lines 88362f614439
  2. 1mo ago First seen · 148 lines · 24 tokens per session scan A f054b03483d1

Subscribe to this mod's changes

database is a cursor rule published in the GitHub repository kok-o/koko-contextos-agents (2 stars, last pushed 1mo ago), licensed MIT. It adds 24 tokens to every session and 1,672 once invoked, about $0.0001 per session on Opus 5.5. 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.