agentleFS
floriscornelfloriscornel/todo-mcp/.cursor/rules/database-patterns.mdc

todo-mcp / rules

Cursor rule2 starsChanged 18 months agoMITView on GitHub

@src/db/schema.ts @src/db/postgres.ts

The file

Show its rules and text

We split this database-patterns.mdc into the rules it gives an agent

14 rules. About 0 are common, 12 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Update Zod validation schemas accordingly

    line 13
  2. Distinctive:

    Ensure type safety between database and validation

    line 14
  3. Distinctive:

    Verify migration works with test database

    line 23
  4. Distinctive:

    Check that rollback is possible if needed

    line 24
  5. Very specific:

    Use the todoDb interface from src/db/index.ts

    line 27
  6. Distinctive:

    All database operations should be type-safe with Drizzle

    line 28
  7. Distinctive:

    Use transactions for operations that modify multiple tables

    line 29
  8. Very specific:

    Use generatedAlwaysAsIdentity() for primary keys

    line 33
  9. Distinctive:

    Use appropriate varchar lengths based on UI constraints

    line 35
  10. Distinctive:

    Keep migrations focused and atomic

    line 39
  11. Distinctive:

    Test migrations with real data scenarios

    line 40
  12. Distinctive:

    Document complex migrations with comments

    line 42
  13. Distinctive:

    Use environment variables for database URLs

    line 45
  14. Distinctive:

    Always close connections in tests

    line 48

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 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
database-patterns.mdc
---
description: 
globs: 
alwaysApply: true
---
# Database Development Patterns

## Schema Changes
When modifying `src/db/schema.ts`:

1. **Update Schema First**:
   - Modify tables in `schema.ts`
   - Update Zod validation schemas accordingly
   - Ensure type safety between database and validation

2. **Generate Migration**:
   ```bash
   npm run db:generate
   ```

3. **Test Migration**:
   - Apply to development database: `npm run db:migrate`
   - Verify migration works with test database
   - Check that rollback is possible if needed

## Database Operations
- Use the `todoDb` interface from `src/db/index.ts`
- All database operations should be type-safe with Drizzle
- Use transactions for operations that modify multiple tables
- Handle database errors gracefully with proper error types

## Schema Patterns
- Use `generatedAlwaysAsIdentity()` for primary keys
- Include `createdAt` timestamp with `defaultNow()`
- Use appropriate varchar lengths based on UI constraints
- Foreign keys should have proper references with cascade rules

## Migration Best Practices
- Keep migrations focused and atomic
- Test migrations with real data scenarios
- Include both up and down migrations when possible
- Document complex migrations with comments

## Connection Management
- Use environment variables for database URLs
- Separate test and development databases
- Connection pooling is handled by the postgres library
- Always close connections in tests

@src/db/schema.ts
@src/db/postgres.ts

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.