database-patterns

Codify PostgreSQL and Supabase schema design, RLS, and migration best practices.

Updated Apr 28, 2025
One-click install
npx skills add https://github.com/tim-o-private/llm-agent --skill database-patterns-tim-o-private
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-patterns
Source: https://github.com/tim-o-private/llm-agent/tree/main/.claude/skills/database-patterns
Command: npx skills add https://github.com/tim-o-private/llm-agent --skill database-patterns-tim-o-private

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a comprehensive guide to designing and maintaining robust, secure, and scalable PostgreSQL databases, specifically within the Supabase ecosystem, preventing common pitfalls and ensuring best practices.

Core Features & Use Cases

  • Database Design Principles: Enforces RLS, UUIDs, proper FKs, and consistent table structures.
  • Migration Management: Guides the creation and application of SQL migrations.
  • Data Access Patterns: Demonstrates secure and efficient data access in Python.
  • Use Case: When creating a new table for user-generated content, ensure it includes RLS policies, UUID primary keys, user_id foreign keys with ON DELETE CASCADE, and created_at/updated_at timestamps, all managed via Supabase migrations.

Quick Start

Use the database-patterns skill to generate a SQL template for a new table that includes RLS, UUID primary keys, and timestamps.

Frequently Asked Questions about database-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Row Level Security (RLS) for user-generated content in Supabase?

Set up Row Level Security (RLS) in Supabase by applying policies that use the is_record_owner() function to restrict data access. This ensures users can only query and modify records where their user_id matches the row's owner.

What is the best way to write SQL migrations to add UUID primary keys and foreign keys in PostgreSQL?

The best way to write SQL migrations for PostgreSQL is to define UUID primary keys and user_id foreign keys with ON DELETE CASCADE. This maintains referential integrity by automatically deleting dependent records when the parent row is removed.

Can I query JSONB data efficiently while maintaining data integrity in PostgreSQL?

Query JSONB data efficiently in PostgreSQL by applying appropriate indexing to the JSONB columns. This approach allows flexible schema storage while maintaining data integrity through consistent table structures and foreign key constraints.

Why does my Supabase database schema design need ON DELETE CASCADE on foreign keys?

Supabase database schema design needs ON DELETE CASCADE on foreign keys to enforce data integrity by automatically removing dependent records. This prevents orphaned rows when a parent record referenced by a UUID foreign key is deleted.

How do I implement secure Python data access patterns with Supabase and PostgreSQL?

Implement secure Python data access patterns with Supabase by writing code that respects RLS policies and uses UUID keys. This approach ensures queries leverage database-level security rules rather than relying solely on application-layer checks.