agentleFS
girijashankarjgirijashankarj/cursor-handbook/.cursor/rules/database/schema-design.mdc

cursor-handbook / database

Cursor rule30 starsChanged 3 months agoMITView on GitHub

Database schema design conventions and standards. Apply when designing schema or migrations.

The file

We split this schema-design.mdc into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use foreign keys with appropriate ON DELETE/UPDATE actions

    line 57
  2. Distinctive:

    Consider denormalization for read-heavy queries

    line 59
  3. Distinctive:

    Use database-level constraints for data integrity

    line 60

≈ “Common” is an estimate: at least 1 in 5 of the 7,324 Cursor rule 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
schema-design.mdc
---
description: "Database schema design conventions and standards. Apply when designing schema or migrations."
alwaysApply: false
globs: "**/*.sql,**/migrations/**/*,**/*.model.ts,**/schema/**/*"
---

# Database Schema Design

## Naming Conventions ({{CONFIG.database.naming}})
| Object | Convention | Example |
|--------|-----------|---------|
| Tables | Plural snake_case | `orders`, `order_items` |
| Columns | snake_case | `created_at`, `order_total` |
| Primary keys | `id` | `id` |
| Foreign keys | `{table_singular}_id` | `order_id`, `user_id` |
| Indexes | `idx_{table}_{columns}` | `idx_orders_user_id` |
| Unique constraints | `uq_{table}_{columns}` | `uq_users_email` |
| Check constraints | `chk_{table}_{description}` | `chk_orders_positive_total` |

## Standard Table Template
```sql
CREATE TABLE {table_name} (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    -- Business columns here
    {{CONFIG.database.softDeleteField}} BOOLEAN NOT NULL DEFAULT true,
    {{CONFIG.database.timestampFields.created}} TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    {{CONFIG.database.timestampFields.updated}} TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    created_by UUID REFERENCES users(id),
    updated_by UUID REFERENCES users(id)
);

-- Auto-update timestamp trigger
CREATE TRIGGER set_updated_at
    BEFORE UPDATE ON {table_name}
    FOR EACH ROW
    EXECUTE FUNCTION update_{{CONFIG.database.timestampFields.updated}}();

-- Default index on soft delete flag
CREATE INDEX idx_{table_name}_active
    ON {table_name}({{CONFIG.database.softDeleteField}})
    WHERE {{CONFIG.database.softDeleteField}} = true;
```

## Data Types
| Use Case | Type | Notes |
|----------|------|-------|
| Identifiers | `UUID` | Use `gen_random_uuid()` |
| Money/currency | `NUMERIC(19,4)` | Never use FLOAT |
| Timestamps | `TIMESTAMP WITH TIME ZONE` | Always timezone-aware |
| Short text | `VARCHAR(n)` | With appropriate length |
| Long text | `TEXT` | For unbounded text |
| Booleans | `BOOLEAN` | Not integers |
| Enums | `VARCHAR` or native ENUM | Prefer VARCHAR for flexibility |
| JSON data | `JSONB` | Not JSON (JSONB is indexed) |

## Relationship Patterns
- Use foreign keys with appropriate ON DELETE/UPDATE actions
- Junction tables for many-to-many relationships
- Consider denormalization for read-heavy queries
- Use database-level constraints for data integrity

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.