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: Generate TypeScript types from Supabase database schema after migration.
Overview
TypeScript types provide type safety for database operations. This guide covers generating types using both CLI (recommended) and MCP approaches. Recommendation: Use CLI for type generation as it provides better error handling and integrates with build scripts.Prerequisites
Verify Setup: MCP Check:Method 1: Generate via CLI (Recommended)
Step 1: Set Project ID
Option A: Environment Variablemcp_supabase_get_project_url() or Supabase dashboard.
Step 2: Generate Types
Using Script:Step 3: Validate Generated Types
CLI:Method 2: Generate via MCP (Alternative)
Step 1: Generate Types
Step 2: Verify Output
The MCP will return generated types. You’ll need to save them to the types file manually. Note: CLI is preferred because:- Better error messages
- Automatic file output
- Integrates with scripts
- More reliable for large schemas
Validation Checklist
After generating types, verify:- File size is substantial (>100KB for 465 tables)
-
npm run typecheckpasses with 0 errors - No empty type definitions (
[_ in never]: never) - All modules have type definitions:
| Module | Expected Tables | Types Present |
|---|---|---|
| Platform Foundation (pf_) | ~74 | [ ] |
| Human Resources (hr_) | ~94 | [ ] |
| Finance & Accounting (fa_) | ~46 | [ ] |
| Forms & Workflow (fw_) | ~54 | [ ] |
| Recovery Housing (rh_) | ~51 | [ ] |
| Governance & Risk (gr_) | ~49 | [ ] |
| Facilities Management (fm_) | ~22 | [ ] |
| Leadership OS (lo_) | ~29 | [ ] |
| IT Service Management (it_) | ~35 | [ ] |
Troubleshooting
Issue: Types file is empty or minimal
Symptoms:types.ts only contains empty type definitions or is very small
Verify Database Has Tables (MCP):
- Verify project ID is correct
- Check Supabase CLI authentication:
supabase login - Try linking project:
supabase link --project-ref <project-ref> - Verify migrations are applied:
mcp_supabase_list_migrations()
Issue: Type errors after generation
Symptoms:npm run typecheck shows errors
Check Database Schema (MCP):
- Review error messages - may indicate schema changes needed
- Check for breaking changes in Supabase client library
- Update code to match new types
- If types are incorrect, restore backup and regenerate
Issue: Missing tables in types
Symptoms: Some tables don’t appear in generated types Verify Tables Exist (MCP):- Verify tables exist in database
- Check table is in
publicschema (default for type generation) - Regenerate types after ensuring all migrations are applied
Issue: CLI command fails
Symptoms:supabase gen types typescript returns error
Check Connection:
- Re-authenticate:
supabase login - Re-link project:
supabase link --project-ref <project-ref> - Check network connectivity
- Try MCP as fallback
When to Regenerate Types
- After applying new migrations
- After schema changes in staging/production
- Before major releases
- When type errors appear in codebase
- After migration validation completes
Backup Strategy
The generate script automatically backs up existing types before generating new ones:- Backup location:
src/integrations/supabase/types.ts.backup.YYYYMMDD_HHMMSS - Restore:
mv src/integrations/supabase/types.ts.backup.* src/integrations/supabase/types.ts
Integration with CI/CD
For automated type generation in CI:Quick Reference
| Task | Tool | Command |
|---|---|---|
| Generate types | CLI | supabase gen types typescript --project-id <id> |
| Generate types | MCP | mcp_supabase_generate_typescript_types() |
| Verify table count | MCP | mcp_supabase_list_tables() |
| Check specific table | MCP | mcp_supabase_execute_sql() |
| Type check | CLI | npm run typecheck |
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