Database

PostgreSQL and MongoDB database design. Schema design, migrations, indexing, query optimization, RLS security policies. Don't use for application logic or API development.

neuron-one 39cda97 1.2 KB Updated

File contents

Database Development

PostgreSQL

  • Normalized schema (3NF minimum)
  • UUID primary keys for distributed systems
  • Created_at/updated_at timestamps on all tables
  • Foreign key constraints with ON DELETE behavior
  • Check constraints for data integrity

Indexing

  • B-tree for equality and range queries
  • GIN for full-text search and JSONB
  • Partial indexes for filtered queries
  • Composite indexes: most selective column first
  • EXPLAIN ANALYZE before and after

Migrations

  • Sequential numbered migrations
  • Always include rollback (down migration)
  • Never modify existing migration
  • Test migration on copy of production data

MongoDB

  • Schema design by access patterns (not normalization)
  • Embedding for 1:few relationships
  • References for 1:many or many:many
  • Compound indexes matching query patterns

Query Optimization

  • Avoid N+1: use JOINs or eager loading
  • Pagination with cursor, not OFFSET
  • Connection pooling (PgBouncer)
  • Read replicas for heavy read workloads

neuron-one/godmode/tree/main/skills/development/database commit 39cda9757a

Frequently asked questions

npx skillmds@latest add neuron-one/database