Version: 2.0.0Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Last Updated: 2026-01-15
Purpose: Run audit SQL scripts against staging database to identify and fix issues.
Overview
This guide explains how to run SQL audit scripts using both MCP (preferred for simple queries) and Dashboard/CLI (for complex scripts). Audits to Run:- RLS Policy Audit - Find UPDATE policies missing WITH CHECK (P0)
- Column Compliance Audit - Find missing audit columns (P1)
- Storage Bucket Audit - Find non-compliant bucket names (P1)
Prerequisites
- Staging Supabase branch/project created
- All migrations applied (
supabase db push) - MCP connection verified or Dashboard access
Audit 1: RLS Policy Audit
Quick Check via MCP
Check for Missing WITH CHECK:Full Audit via Dashboard
For generating fix statements, use the full audit script:- Go to Supabase Dashboard → SQL Editor
- Copy contents of
scripts/audit-rls-policies.sql - Run the script
- Save Query 3 output - Contains
ALTER POLICYfix statements
Expected Results
| Query | Purpose | Expected Before Fix | Expected After Fix |
|---|---|---|---|
| Query 1 | List all UPDATE policies | ~118 missing | 0 missing |
| Query 2 | Summary by command | - | - |
| Query 3 | Generate fix statements | 118 statements | Empty |
Audit 2: Column Compliance Audit
Quick Check via MCP
Check for Missing updated_by:Full Audit via Dashboard
For generating fix statements:- Go to Supabase Dashboard → SQL Editor
- Copy contents of
scripts/audit-table-columns.sql - Run the script
- Save Query 4 output - Contains
ADD COLUMNstatements
Expected Results
| Query | Purpose | Expected Before Fix | Expected After Fix |
|---|---|---|---|
| Query 1 | Missing organization_id | Review list | Verified needed |
| Query 2 | Missing audit columns | ~60 tables | 0 tables |
| Query 4 | Generate fix statements | 60+ statements | Empty |
Audit 3: Storage Bucket Audit
Quick Check via MCP
Check for Non-Compliant Buckets:Full Audit via Dashboard
For generating fix statements:- Go to Supabase Dashboard → SQL Editor
- Copy contents of
scripts/audit-storage-buckets.sql - Run the script
- Save Query 3 output - Contains rename statements
Expected Results
| Query | Purpose | Expected Before Fix | Expected After Fix |
|---|---|---|---|
| Query 1 | All buckets | ~7 buckets | ~7 buckets |
| Query 2 | Object counts | - | - |
| Query 3 | Generate rename statements | 4 statements | Empty |
Creating Fix Migrations
After running audits, create migrations from the results:Step 1: Create Migration Files
Use CLI:Step 2: Fill with Audit Output
Copy the fix statements from each audit into the corresponding migration file. RLS Fix Example:Step 3: Apply and Verify
Use CLI:Quick Reference: MCP vs Dashboard
| Task | Use MCP | Use Dashboard |
|---|---|---|
| Quick count queries | ✅ | |
| List first 20 results | ✅ | |
| Full audit script | ✅ | |
| Generate fix statements | ✅ | |
| Complex multi-query scripts | ✅ | |
| Save results to file | ✅ |
Troubleshooting
Issue: MCP Query Times Out
Solution: Use Dashboard for complex queries. MCP has execution limits.Issue: Query Returns Empty
Solution: Verify migrations applied. Check table exists with:Issue: Fix Statement Syntax Error
Solution: Review generated SQL. Some complex policies may need manual adjustment.Issue: Permission Denied
Solution: Check RLS policies on system tables. Use Dashboard SQL Editor which bypasses RLS.Output File Locations
Save audit results to:reports/audits/rls-fix-statements.sqlreports/audits/column-fix-statements.sqlreports/audits/storage-fix-statements.sql
Next Steps
After completing audits:- Create fix migrations using templates
- Apply to staging:
supabase db push - Re-run audits to verify all issues resolved
- Generate TypeScript types: See TYPE_GENERATION_GUIDE.md
Related Documentation
- Completion Plan - Full migration workflow
- MCP Usage Guide - When to use MCP vs CLI
- Pre-Production Checklist - Final validation
Last Updated: 2026-01-15
Version: 2.0.0