sql-migrations

A set of rules for SQL migration files, which record database structure changes such as tables, columns, indexes, triggers, and data types.

In plain words
What is it for?
Use it when creating or changing database schemas, naming migration files, adding indexes or columns, and writing matching forward and rollback changes.
Why use it?
It prevents different environments from ending up with different database structures by keeping schema changes in an append-only history.

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/golid-ai/golid/sql-migrations
Clone the repo
git clone --depth 1 https://github.com/golid-ai/golid

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,000 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.01000
Opus 5 $0.00000 $0.00500
Sonnet 5 $0.00000 $0.00200
Haiku 4.5 $0.00000 $0.00100

Measured 2d ago against content hash 7496b38d03c5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

sql-migrations 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 2d 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/sql-migrations.mdc · 116 lines

How it starts

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

SQL Migration Patterns

Thesis: Migrations are the source of truth for the data model. Every table gets UUIDs, TIMESTAMPTZ, FK indexes, and an updated_at trigger.

Reference files: 000001_init.up.sql

File Naming

000NNN_description.up.sql and 000NNN_description.down.sql — always create both.

Once Committed, Never Edited

Migrations are append-only history. Once a migration file is committed, even on a feature branch, do not modify it. Any schema change goes in a new migration with the next sequence number.

  • Need to add a column? New ALTER TABLE ... ADD COLUMN.
  • Need to drop a column you just added? New ALTER TABLE ... DROP COLUMN.
  • Forgot an index? New CREATE INDEX.

Editing an already-committed .up.sql silently desyncs schemas: any environment that ran the old version will never pick up the change, while fresh databases will. Before editing any 00NN_*.sql file, ask: "is this committed?" If yes, create a new migration.

Up Migration

-- Enums first
CREATE TYPE item_status AS ENUM ('new', 'in_progress', 'complete', 'cancelled');

-- Tables (with UUID PKs, timestamps, FKs with ON DELETE CASCADE)
CREATE TABLE items (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  title TEXT NOT NULL,
  status item_status DEFAULT 'new',
  created_at TIMESTAMPTZ DEFAULT NOW(),
  updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- Indexes on FKs and frequently filtered columns
CREATE INDEX idx_items_user_id ON items(user_id);
CREATE INDEX idx_items_status ON items(status);

-- Reuse the existing updated_at trigger function
CREATE TRIGGER items_updated_at BEFORE
UPDATE ON items FOR EACH ROW EXECUTE FUNCTION update_updated_at();

Down Migration

Drop in reverse dependency order: columns (ALTER), then tables, then enums.

DROP TABLE IF EXISTS item_history;
DROP TABLE IF EXISTS items;
DROP TYPE IF EXISTS item_status;

Conventions

  • UUIDs for all primary keys (not serial/bigint).
  • TIMESTAMPTZ for all timestamps (not TIMESTAMP).
  • TEXT for strings (not VARCHAR) — PostgreSQL treats them identically.
  • DECIMAL(x,2) for money/hours (not FLOAT).
  • JSONB for structured metadata (audit trails, preferences).
  • TEXT[] for tag-like arrays (skills, industries).
  • Enums for finite status sets — add a cancelled state if the entity can be deactivated.
  • ON DELETE CASCADE on child table FKs.
  • Index every FK and every column used in WHERE filters.
  • updated_at trigger on every table that has the column.

Read the full file on GitHub · 116 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. 2d ago First seen · 116 lines · 0 tokens per session scan A 7496b38d03c5

Subscribe to this mod's changes

sql-migrations is a cursor rule published in the GitHub repository golid-ai/golid (40 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,000 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.