postgres-ecosystem
Skill3 starsChanged 10 days agoMITView on GitHub
Activate this skill for PostgreSQL, Supabase, Neon databases, complex SQL queries, migrations, or Row Level Security (RLS). Use when designing schemas, tuning queries, writing safe migrations, or enforcing multi-tenant isolation.
We split this skill into the rules it gives an agent
21 rules. About 0 are common, 9 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 31
Always use NOT NULL unless a column is genuinely optional.
- Very specific: line 33
Use UUIDv7 or BIGINT GENERATED ALWAYS AS IDENTITY for primary keys.
- Very specific: line 34
Use native types: timestamptz for all timestamps, text over arbitrary varchar(255), jsonb over json.
- Distinctive: line 38
Default to 3NF (Third Normal Form) for transactional integrity.
- Very specific: line 39
Use jsonb only for semi-structured data, dynamic user attributes, or audit logs.
- Very specific: line 40
When querying inside jsonb, create GIN indexes (CREATE INDEX ON table USING gin (data jsonb_path_ops);) or expression indexes on specific …
- Very specific: line 53
Separate policies per action: Do not use FOR ALL for combined read/write logic.
- Very specific: line 77
Recursive policies: If policy on table A queries table A, it causes infinite recursion.
- Very specific: line 88
Add columns with default values without lock in modern Postgres (ALTER TABLE t ADD COLUMN c text DEFAULT 'x' is instant in Postgres 11+).
- Very specific: line 89
Create indexes concurrently: CREATE INDEX CONCURRENTLY idx_orders_customer ON orders (customer_id).
- Very specific: line 90
Never add a NOT NULL constraint to an existing column without a CHECK ...
- Distinctive: line 93
When renaming or restructuring a column:
- Distinctive: line 94
Phase 1 (Expand): Add the new column alongside the old.
- Distinctive: line 104
Always examine execution plans using:
- Very specific: line 115
B-Tree: Default for equality (=), range (<, <=, >, >=), and BETWEEN queries.
- Distinctive: line 120
Composite Index Column Order: Put equality columns first, followed by range/sorting columns (Left-to-Right prefix rule).
- Distinctive: line 128
Use Neon branches in CI pipelines to provision an instant, copy-on-write database clone per Pull Request.
- Distinctive: line 129
Run database migrations against the PR branch, run integration and E2E tests, and terminate the branch automatically upon PR merge or …
- Distinctive: line 130
Never run manual experimental queries against production compute.
- Distinctive: line 134
Ensure Edge Functions verify authorization headers and validate JWTs before executing business logic.
- Very specific: line 135
Run scheduled maintenance (VACUUM ANALYZE) on heavily churned tables to control table bloat.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill 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.
Files
PostgreSQL & Modern Cloud Database Ecosystem
Scope: Covers PostgreSQL core principles, Supabase architecture & RLS security, Neon branching & serverless workflows, query optimization, indexing strategies, and zero-downtime database migrations.
When to Activate
- Designing relational database schemas and constraints
- Implementing or auditing Row Level Security (RLS) policies
- Supabase integrations (Auth, Storage, Edge Functions, Realtime)
- Neon database branching for CI/CD and pull request environments
- Writing safe, reversible SQL migrations
- Optimizing slow queries with
EXPLAIN (ANALYZE, BUFFERS) - Establishing indexing strategies (B-Tree, GIN, BRIN, Partial, Expression)
- Connection pooling and scaling (PgBouncer, Supavisor)
1. Schema Design Principles
Strict Constraints & Integrity
- Always use
NOT NULLunless a column is genuinely optional. - Explicitly define foreign key constraints with sensible
ON DELETEbehavior (CASCADE,RESTRICT, orSET NULL). - Use UUIDv7 or
BIGINT GENERATED ALWAYS AS IDENTITYfor primary keys. UUIDv7 provides time-sortable random keys that reduce B-tree index fragmentation. - Use native types:
timestamptzfor all timestamps,textover arbitraryvarchar(255),jsonboverjson. - Enforce business invariants using
CHECKconstraints (e.g.,CHECK (price >= 0),CHECK (end_date >= start_date)).
Normalization vs Pragmatic Denormalization
- Default to 3NF (Third Normal Form) for transactional integrity.
- Use
jsonbonly for semi-structured data, dynamic user attributes, or audit logs. - When querying inside
jsonb, create GIN indexes (CREATE INDEX ON table USING gin (data jsonb_path_ops);) or expression indexes on specific keys.
2. Row Level Security (RLS) & Multi-Tenant Isolation
Universal RLS Rules
- Always enable RLS explicitly:
ALTER TABLE organizations ENABLE ROW LEVEL SECURITY; ALTER TABLE organizations FORCE ROW LEVEL SECURITY; -- Forces RLS on table owners/superusers if supported - Deny by default: In PostgreSQL, enabling RLS without policies denies all operations except for superusers.
- Separate policies per action: Do not use
FOR ALLfor combined read/write logic. Write distinct policies forSELECT,INSERT,UPDATE, andDELETE.
Supabase RLS Patterns
-- Pattern: Multi-tenant tenant_id matching authenticated user
CREATE POLICY "Users can view members of their organization"
ON org_members FOR SELECT
TO authenticated
USING (
org_id IN (
SELECT om.org_id FROM org_members om WHERE om.user_id = auth.uid()
)
);
-- Pattern: Ownership-based mutations
CREATE POLICY "Users can update their own profile"
ON profiles FOR UPDATE
TO authenticated
USING (id = auth.uid())
WITH CHECK (id = auth.uid());Critical RLS Traps to Avoid
- Never expose
service_roleor postgres admin keys in client bundles. Only publicanonkeys belong in the client. - Recursive policies: If policy on table
Aqueries tableA, it causes infinite recursion. Use helper security-definer functions or JWT metadata claims where appropriate. - Index RLS filter columns: Columns evaluated in
USINGclauses (such asuser_id,org_id,tenant_id) MUST have indexes, otherwise every single row lookup triggers a sequential table scan.
3. Safe, Zero-Downtime Migrations
The Golden Rules of Production Migrations
- Never perform destructive schema changes in a single deployment.
- Always write reversible migrations with a verified rollback script.
- Avoid table locks on large tables:
- Add columns with default values without lock in modern Postgres (
ALTER TABLE t ADD COLUMN c text DEFAULT 'x'is instant in Postgres 11+). - Create indexes concurrently:
CREATE INDEX CONCURRENTLY idx_orders_customer ON orders (customer_id); - Never add a
NOT NULLconstraint to an existing column without aCHECK ... NOT VALIDfollowed byVALIDATE CONSTRAINT.
- Add columns with default values without lock in modern Postgres (
Expand and Contract Migration Lifecycle
When renaming or restructuring a column:
- Phase 1 (Expand): Add the new column alongside the old. Dual-write to both old and new columns in the application code.
- Phase 2 (Backfill): Backfill historical data in small batched transactions to prevent replication lag and transaction lockouts.
- Phase 3 (Switch): Switch application reads to the new column.
- Phase 4 (Contract): Drop old column and stop writing to it after safe monitoring period.
4. Query Optimization & Indexing
Diagnosis with EXPLAIN
Always examine execution plans using:
EXPLAIN (ANALYZE, BUFFERS, VERBOSE, COSTS)
SELECT * FROM orders WHERE status = 'pending' AND created_at > NOW() - INTERVAL '7 days';Look for:
- Seq Scan on large tables: Indicates missing or non-selective index.
- Rows Removed by Filter: A high number indicates the index didn't filter early enough.
- Buffers: shared read: Indicates data was read from disk rather than OS/Postgres shared buffer cache.
Strategic Index Types
- B-Tree: Default for equality (
=), range (<,<=,>,>=), andBETWEENqueries. - Partial Index: Great for filtering sub-states:
CREATE INDEX idx_unprocessed_jobs ON jobs (priority DESC, created_at ASC) WHERE status = 'pending'; - Composite Index Column Order: Put equality columns first, followed by range/sorting columns (Left-to-Right prefix rule).
- GIN Index: For arrays, full-text search (
tsvector), andjsonb.
5. Cloud Platforms: Supabase & Neon Workflows
Neon Database Branching
- Use Neon branches in CI pipelines to provision an instant, copy-on-write database clone per Pull Request.
- Run database migrations against the PR branch, run integration and E2E tests, and terminate the branch automatically upon PR merge or closure.
- Never run manual experimental queries against production compute; spin up a point-in-time branch to safely test queries on production-scale data.
Supabase Edge & Storage
- Validate all file uploads with explicit Storage bucket security policies.
- Ensure Edge Functions verify authorization headers and validate JWTs before executing business logic.
- Run scheduled maintenance (
VACUUM ANALYZE) on heavily churned tables to control table bloat.
In this repository50 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/always-on.mdcCursor rule
- 3d-visualsSkill
- agent-researchSkill
- api-architectureSkill
- assets-mediaSkill
- cavemanSkill
- cloudflare-expertSkill
- devops-cicdSkill
- firebase-expertSkill
- git-collaborationSkill
- gravitasSkill
- gsd-coreSkill
- llm-optimizationSkill
- mobile-engineeringSkill
- ponytailSkill
- security-auditorSkill
- sentry-expertSkill
- seo-marketingSkill
- state-managementSkill
- testing-qaSkill
- ui-ux-pro-maxSkill
- ux-researchSkill
- web-animationSkill
- web-gamedevSkill
- 3d-visualsSkill
- agent-researchSkill
- api-architectureSkill
- assets-mediaSkill
- cavemanSkill
- cloudflare-expertSkill
- devops-cicdSkill
- firebase-expertSkill
- git-collaborationSkill
- gravitasSkill
- gsd-coreSkill
- llm-optimizationSkill
- mobile-engineeringSkill
- ponytailSkill
- postgres-ecosystemSkill
- security-auditorSkill
- sentry-expertSkill
- seo-marketingSkill
- state-managementSkill
- testing-qaSkill
- ui-ux-pro-maxSkill
- ux-researchSkill
- web-animationSkill
- web-gamedevSkill
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
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.

