Skip to content

feat: supabase db references#17

Merged
Rodriguespn merged 2 commits intofeature/supabase-skillfrom
feature/supabase-db-references
Jan 27, 2026
Merged

feat: supabase db references#17
Rodriguespn merged 2 commits intofeature/supabase-skillfrom
feature/supabase-db-references

Conversation

@Rodriguespn
Copy link
Collaborator

@Rodriguespn Rodriguespn commented Jan 27, 2026

What kind of change does this PR introduce?

New skill references for Supabase database management and best practices.

What is the current behavior?

No existing reference files for database-specific topics in the Supabase skill. The skill structure and build system were recently established, but database references had not yet been implemented.

What is the new behavior?

Comprehensive database guidance organized into six focused categories covering the most critical aspects of working with Supabase's PostgreSQL database.

Reference Structure

The database references are organized into six categories: Row Level Security (RLS), Connection Pooling, Schema Design, Migrations, Performance, and Security.

  • Row Level Security (RLS)

    • Covers policy patterns, common mistakes, and performance tuning
    • Emphasizes importance of correct RLS configuration in Supabase
    • Includes PERMISSIVE vs RESTRICTIVE policies, mandatory RLS, views, and pitfalls
  • Connection Pooling

    • Focuses on Supavisor pooling modes
    • Explains Transaction mode (port 6543) vs Session mode (port 5432)
    • Highlights risks of connection exhaustion and prepared statement incompatibilities
  • Schema Design

    • Supabase-specific design patterns
    • auth.users foreign keys with CASCADE
    • Best practices for timestamptz, JSONB + indexing, PostgreSQL extensions, and Realtime
    • Prevents orphaned records and improves Supabase integration
  • Migrations

    • Using Supabase CLI for schema changes
    • Idempotent migration patterns
    • Local testing with supabase db reset
    • Generating migrations with supabase db diff
  • Performance

    • Index selection guidance (B-tree, BRIN, GIN, partial)
    • Query optimization for PostgREST
    • Notes potential 10–1000x performance improvements with proper indexing
  • Security

    • Service role key handling (bypasses all RLS)
    • Warning to never expose service role key to browsers
    • Use of security definer functions in private schemas for elevated operations

Key Topics Covered

  • RLS mandatory enablement: Preventing unauthorized data access by enabling RLS on all exposed tables
  • Connection pooling modes: Transaction vs Session mode selection for serverless vs long-running applications
  • auth.users CASCADE constraints: Preventing orphaned records and user deletion failures
  • Idempotent migrations: Writing safe migrations with IF NOT EXISTS/IF EXISTS patterns
  • Index type selection: Choosing between B-tree, BRIN, GIN, and partial indexes based on query patterns
  • Service role key security: Preventing complete database compromise by never exposing the service_role key to browsers
  • RLS policy types: Using PERMISSIVE (OR logic) vs RESTRICTIVE (AND logic) policies correctly
  • Timestamp patterns: Using timestamptz for consistency with Supabase Auth
  • JSONB optimization: Proper indexing strategies for JSON columns with GIN indexes
  • Migration testing: Local validation workflows with supabase db reset before production deployment
  • Security definer functions: Implementing elevated operations safely with proper search_path configuration

Sources

Documentation and references consulted:

Design Decisions

  • Common mistakes emphasis: Each reference file uses an "Incorrect/Correct" pattern showing anti-patterns first, then the proper solution. This pattern was chosen because agents frequently need to help users debug existing code, and seeing common mistakes helps them identify issues faster. The incorrect examples are concrete and represent real production issues observed in Supabase projects.

  • Supabase-specific focus: Intentionally excluded generic PostgreSQL guidance that Claude already knows (like basic SELECT queries or standard table creation). Instead, focused exclusively on Supabase-specific patterns like auth.uid() usage, Supavisor configuration, and Supabase CLI workflows. This maximizes the value-per-token of each reference.

@Rodriguespn Rodriguespn requested review from a team, gregnr, mattrossman and samrose January 27, 2026 18:32
@Rodriguespn Rodriguespn self-assigned this Jan 27, 2026
@Rodriguespn Rodriguespn force-pushed the feature/supabase-db-references branch 2 times, most recently from bdc02f2 to ec1c963 Compare January 27, 2026 18:43
@Rodriguespn Rodriguespn force-pushed the feature/supabase-skill branch from 9cab06c to 803e968 Compare January 27, 2026 18:44
@Rodriguespn Rodriguespn force-pushed the feature/supabase-db-references branch from ec1c963 to fb2e38b Compare January 27, 2026 19:00
@Rodriguespn Rodriguespn force-pushed the feature/supabase-db-references branch from fb2e38b to c52ca28 Compare January 27, 2026 21:41
@Rodriguespn Rodriguespn force-pushed the feature/supabase-skill branch from 803e968 to f856e34 Compare January 27, 2026 21:41
Rodriguespn and others added 2 commits January 27, 2026 21:48
Move all database reference files to references/db/ to organize
by product area and take advantage of the new subdirectory support
in the build system.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@Rodriguespn Rodriguespn force-pushed the feature/supabase-db-references branch from 5c43b10 to 9919eab Compare January 27, 2026 21:48
@Rodriguespn Rodriguespn marked this pull request as ready for review January 27, 2026 22:05
@Rodriguespn Rodriguespn merged commit 0277e96 into feature/supabase-skill Jan 27, 2026
2 checks passed
@Rodriguespn Rodriguespn deleted the feature/supabase-db-references branch January 27, 2026 22:05
@Rodriguespn Rodriguespn added the new-rule Adding a new rule(s) to a skill label Jan 27, 2026
Rodriguespn added a commit that referenced this pull request Jan 28, 2026
* feat: supabase db references

* refactor: move database references to db subdirectory

Move all database reference files to references/db/ to organize
by product area and take advantage of the new subdirectory support
in the build system.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
Rodriguespn added a commit that referenced this pull request Jan 28, 2026
* feat: supabase db references

* refactor: move database references to db subdirectory

Move all database reference files to references/db/ to organize
by product area and take advantage of the new subdirectory support
in the build system.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
Rodriguespn added a commit that referenced this pull request Jan 30, 2026
* feat: supabase db references

* refactor: move database references to db subdirectory

Move all database reference files to references/db/ to organize
by product area and take advantage of the new subdirectory support
in the build system.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-rule Adding a new rule(s) to a skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants