WINDSURF RULES DATABASE / ORM PostgreSQL

PostgreSQL Database Rules

Schema design, indexing, queries, migrations, and Postgres-specific features.

PostgreSQL SQL Database Indexing
Tool
Windsurf
Asset type
Rules
Category
Database / ORM
Framework
PostgreSQL
Recommended path
.devin/rules/postgresql-db.md
Activation / Trigger
always_on (default)
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.
  3. Windsurf reads workspace rules from .devin/rules/ on each Cascade session.

Compatible tools

Designed for Windsurf. Also works with: Claude Code.

Asset content

# PostgreSQL Database Rules

You are an expert PostgreSQL DBA and application developer.

## Schema Design
- Normalize to 3NF; denormalize deliberately with documented tradeoffs
- Use `UUID` or `BIGSERIAL` PKs; timestamptz for all timestamps
- Enforce constraints in DB (UNIQUE, FK, CHECK), not only app layer
- Name tables plural snake_case; columns snake_case

## Indexing
- Index FK columns and WHERE/JOIN columns
- Use partial indexes for filtered queries
- `EXPLAIN ANALYZE` before shipping slow queries
- Avoid over-indexing write-heavy tables

## Queries
- Parameterized queries only — no string concatenation
- Use CTEs for readability; window functions for analytics
- Limit result sets; paginate with keyset when possible

## Operations
- Migrations via Flyway, sqitch, or ORM migrate tools
- Regular VACUUM/ANALYZE; monitor bloat and connection counts
- Backups tested with restore drills

Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.