supabase-schema-db-drift-guard

Prevents Supabase schema drift and PostgREST cache errors in measurement pipeline migrations and edge function writes.

Updated Sep 24, 2025
One-click install
npx skills add https://github.com/chriso789/pitch-1 --skill supabase-schema-db-drift-guard-chriso789
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-schema-db-drift-guard
Source: https://github.com/chriso789/pitch-1/tree/main/.agents/skills/supabase-schema-db-drift-guard
Command: npx skills add https://github.com/chriso789/pitch-1 --skill supabase-schema-db-drift-guard-chriso789

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Supabase projects suffer from schema drift when new columns are added without guards, edge functions crash on PostgREST schema-cache errors (PGRST204/PGRST205), and diagnostic fields pollute the database schema. This Skill enforces a strict classification of stable DB columns versus JSONB debug fields so migrations and edge function writes never cause missing-column 400s or silently dropped diagnostics. ## Core Features & Use Cases - Field Classification Enforcement: Decides whether each new field becomes a stable DB column (queried, indexed, RLS-referenced) or lives inside geometry_report_json / source_context as JSONB. - Migration Guardrails: Requires IF NOT EXISTS guards, RLS impact notes, and NOTIFY pgrst reload statements on every migration touching roof_measurements, ai_measurement_jobs, or measurement_jobs. - Safe Edge Function Writes: Mandates strip-and-retry logic for PostgREST schema-cache errors, preserving removed fields in geometry_report_json.schema_drift_stripped_columns. - Result State Normalization: Locks result_state to a 10-bucket enum and routes specific solver failures to hard_fail_reason, failure_stage, and failure_details instead. - Use Case: When adding a new diagnostic payload to the AI measurement pipeline, the Skill tells you to nest it under geometry_report_json rather than creating a new column, and verifies the edge function write path has schema-cache retry handling. ## Quick Start Review my new Supabase migration and edge function insert for the roof_measurements table and confirm it follows the schema drift guard rules.

Frequently Asked Questions about supabase-schema-db-drift-guard

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

FAQPage Schema
How do I prevent PostgREST schema cache errors in Supabase edge functions?▼

Strip unknown optional columns before insert or update, and on PGRST204 or 'Could not find column' errors retry the write with the offending diagnostic columns removed. Preserve every stripped field inside geometry_report_json.schema_drift_stripped_columns so no data is silently lost.

When should I add a database column versus storing data in JSONB in Supabase?▼

Add a DB column only for workflow fields that are queried, filtered, indexed, or referenced by RLS policies. Large or evolving diagnostic payloads, phase blocks, and debug objects belong in JSONB columns like geometry_report_json, since adding a column per debug object causes schema drift.

What should every Supabase migration include to avoid schema drift?▼

Every migration needs IF NOT EXISTS or IF EXISTS guards, an explicit RLS impact note for tables with row-level security, and a NOTIFY pgrst, 'reload schema' statement at the end so PostgREST picks up changes without a manual reload.

Why does my Supabase insert fail with PGRST204 after adding a column?▼

PGRST204 occurs when PostgREST's schema cache has not picked up the new column. Add NOTIFY pgrst, 'reload schema' to the migration, and make edge function writes defensively strip and retry on schema-cache errors.

Can I add new values to the result_state enum for specific solver failures?▼

No. result_state is locked to a 10-bucket normalized enum written via normalizeResultStateForWrite. Specific solver failures go into hard_fail_reason, block_customer_report_reason, failure_stage, and geometry_report_json.failure_details instead of expanding the CHECK constraint.