07-database-development

A set of rules for designing databases that use SQLite through Cloudflare D1 and Drizzle. It covers data types, relationships, validation, and SQL naming.

In plain words
What is it for?
Use it when creating or changing tables, columns, foreign keys, indexes, or database validation in a Cloudflare D1 project.
Why use it?
It helps avoid unclear table relationships, unsafe values, and mismatches between database fields and TypeScript code.

Cursor rule for Cursor

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.

agentmods
npx agentmods add rules/dafthunk-com/dafthunk/07-database-development
Clone the repo
git clone --depth 1 https://github.com/dafthunk-com/dafthunk

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 536 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.00536
Opus 5 $0.00000 $0.00268
Sonnet 5 $0.00000 $0.00107
Haiku 4.5 $0.00000 $0.00054

Measured yesterday against content hash 512f03c3cc9c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

07-database-development 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 yesterday.

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/07-database-development.mdc · 72 lines

How it starts

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

Database Design Best Practices

Use SQL-Compatible Types

  • Cloudflare D1 uses SQLite under the hood.
  • Use Drizzle's SQLite helpers (integer(), text(), sqliteTable(), etc.).
  • Be mindful of SQLite's flexible typing and ensure type safety using Drizzle.
export const users = sqliteTable("users", {
  id: integer("id").primaryKey({ autoIncrement: true }),
  email: text("email").notNull().unique(),
  createdAt: text("created_at").default(sql`CURRENT_TIMESTAMP`),
});

Model Relationships Carefully

  • D1 (SQLite) does support foreign keys, but indexing is crucial for performance.
  • Use .references() in Drizzle to define relationships explicitly.
export const posts = sqliteTable("posts", {
  id: integer("id").primaryKey({ autoIncrement: true }),
  authorId: integer("author_id").references(() => users.id),
  title: text("title").notNull(),
});

Use Enums Where Needed (with Caution)

  • SQLite does not have native enum support.
  • Instead, constrain values manually in your application or through custom Zod validation.

Use snake_case for SQL Fields

  • Stick to snake_case in table and column names.
  • Use camelCase in TypeScript with InferModel.
export const tasks = sqliteTable("tasks", {
  createdAt: text("created_at"),
});

Timestamps & Defaults

  • Use SQL-level defaults like CURRENT_TIMESTAMP to avoid time zone mismatches.
  • Avoid setting defaults in TypeScript for critical database fields.

Type Inference

  • Always use Drizzle's InferModel to export consistent types.
export type User = InferModel<typeof users>;
export type NewUser = InferModel<typeof users, "insert">;

Migrations

  • Use drizzle-kit to generate and run migrations.
  • Keep migrations version-controlled and consistent across environments.
  • Don't mutate tables manually in production.

Avoid Nullable Unless Necessary

  • Prefer strict types to nullable columns.
  • Design schema around clear assumptions; nulls can be a source of bugs.

Read the full file on GitHub · 72 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. yesterday First seen · 72 lines · 0 tokens per session scan A 512f03c3cc9c

Subscribe to this mod's changes

07-database-development is a cursor rule published in the GitHub repository dafthunk-com/dafthunk (119 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 536 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-30.