database-and-migrations

Applies and audits Supabase Postgres migrations across sandbox and production projects.

1|Updated May 23, 2026
One-click install
npx skills add https://github.com/palfish-t-i-u/palfish-t-i-u-h-th-ng-ver-2 --skill database-and-migrations-palfish-t-i-u
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-and-migrations
Source: https://github.com/palfish-t-i-u/palfish-t-i-u-h-th-ng-ver-2/tree/main/.claude/skills/database-and-migrations
Command: npx skills add https://github.com/palfish-t-i-u/palfish-t-i-u-h-th-ng-ver-2 --skill database-and-migrations-palfish-t-i-u

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Managing a two-project Supabase setup with dozens of manually applied SQL migration files is error-prone: files live in three different locations, one critical DDL file sits outside the numbered sequence, and PostgREST caches the schema until notified. This Skill encodes the authoritative migration order, sandbox-first workflow, and known traps so schema changes are applied consistently and safely. ## Core Features & Use Cases - Authoritative migration order: Lists all Layer 1 patch files, dated docs/migrations, and backend/migrations in exact replay order, including the out-of-sequence notifications/exchange_rates DDL that is easy to miss on sandbox reset. - Safe migration procedures: Sandbox-first workflow, SELECT-preview before data-mutating changes, mandatory NOTIFY pgrst schema reload, and named backup-table convention before destructive operations. - Diagnostics and schema inventory: Key table inventory with creating migration, atomic RPC functions for ID allocation, seed/cleanup script usage, and fixes for known incidents like 503 errors from missing RPCs and SePay timezone double-shifts. - Use Case: After resetting the sandbox environment, replay the full migration history in the documented order, seed nhan_su_sale, and verify RPC functions exist before pointing the backend at the fresh database. ## Quick Start Apply the pending migration file to the sandbox Supabase project, end it with NOTIFY pgrst reload schema, and verify the new column exists before touching production.

Frequently Asked Questions about database-and-migrations

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

FAQPage Schema
How do I apply a Supabase migration without a CLI runner?

Copy the SQL file contents into the Supabase SQL Editor for the target project and run it manually. Always end with NOTIFY pgrst, 'reload schema'; because PostgREST caches the schema and will not see new columns or functions until notified.

How do I set up a fresh Supabase sandbox environment?

Replay the full migration history in order: numbered patch files first, then named patches, then docs/sql/notifications_exchange_rates.sql, then dated docs/migrations and backend/migrations files. Finish by running scripts/seed_nhan_su_sale.py to seed the sales staff table.

Why does the backend return 503 errors mentioning rpc_helpers?

A 503 from rpc_helpers.py means a required RPC function is missing, usually because docs/supabase_schema_patch_db_audit_20260603.sql was not applied or was applied to the wrong project. Apply that migration and run NOTIFY pgrst, 'reload schema'; to fix it.

Should I apply migrations to production or sandbox first?

Always apply to sandbox first and smoke-test the affected feature. Only apply to production after the main branch is merged and deployed to Render, so the deployed code matches the production schema.

Why do new Supabase columns not appear in API responses?

PostgREST caches the database schema, so new columns or functions are invisible until the cache is refreshed. Run NOTIFY pgrst, 'reload schema'; in the SQL Editor immediately after applying any migration.

What should I do before running a destructive data cleanup?

Create a named backup table first, for example CREATE TABLE so_doanh_thu_backup AS SELECT * FROM so_doanh_thu. Then run cleanup scripts like cleanup_so_doanh_thu.py with --dry-run before using --apply.