supabase-production-ops
Safe Supabase production operations, migration deployments, database connection pooling, RLS auditing, and backup verification for LKDV.
SKILL.md.agents/skills/supabase-production-ops/SKILL.md
GitHubSupabase Production Operations & Auditing
This skill governs all production database operations on Supabase for Le Kit du Voyageur (LKDV), targeting project icxyvwzfjbflcbqukpfz.
1. Safety Rules & Production Migrations
- Zero Data Loss Principle:
- Never run
DROP TABLEor destructiveALTER TABLE ... DROP COLUMNdirectly in production. - Follow the two-phase migration pattern: Expand (add column/function) -> Backfill & Deploy code -> Contract (cleanup deprecated schema).
- Never run
- Migration Deployment:
- All migrations are tracked in
supabase/migrations/with UTC timestamps. - Test migrations locally with
npx supabase db resetor test harness before proposing execution in production. - Tony applies migrations to production via the Supabase Dashboard SQL Editor or via the Supabase CLI (
npx supabase db push) when authorized.
- All migrations are tracked in
2. Row Level Security (RLS) & PostGIS Indexing
- RLS Mandatory on 100% of Public Tables:
- Every table created must immediately have:
ALTER TABLE public.<table_name> ENABLE ROW LEVEL SECURITY; - Standard policy template:
CREATE POLICY "Users can only view their own items" ON public.<table_name> FOR SELECT USING (auth.uid() = user_id);
- Every table created must immediately have:
- PostGIS Performance:
- All spatial query columns (
geogorgeomwith SRID 4326) MUST have a GiST or SP-GiST index:CREATE INDEX IF NOT EXISTS idx_<table_name>_geom ON public.<table_name> USING GIST (geom); - Use
ST_DWithinwith geography or spatial indexes instead of computing Cartesian distance on huge tables.
- All spatial query columns (
3. Connection Pooling & Resource Health
- Supavisor / Transaction Pooling:
- Always connect serverless Next.js functions via the transaction pooler port (6543) with
pgbouncer=truequery parameter for high concurrency. - Reserve direct session connections (port 5432) strictly for long-running administrative migrations.
- Always connect serverless Next.js functions via the transaction pooler port (6543) with
- Monitoring & Alerts:
- Monitor database CPU, connection count, and disk IOPS in the Supabase Dashboard.
- Verify that
SECURITY DEFINERfunctions have explicitsearch_path = public, pg_temp;.
4. Supabase MCP & CLI Tools
- Supabase MCP Server:
- Query project metadata, schema introspection, table structures, and run verified diagnostic queries.
- Supabase CLI:
supabase migration listsupabase gen types typescript --project-id icxyvwzfjbflcbqukpfz > src/lib/supabase/types.tssupabase db lint