Automated TypeScript type generation from Supabase database schema to ensure type safety across the platform.
Run npm run types:generate to generate TypeScript types from the production Supabase database.
Requirements:
SUPABASE_ACCESS_TOKEN environment variable setnpm install)Run npm run types:generate:local to generate TypeScript types from local Supabase instance.
Requirements:
supabase start)Run npm run types:check to verify that Supabase types file exists and contains expected type definitions.
Checks:
The .github/workflows/update-supabase-types.yml workflow automatically updates types:
Configure these in GitHub repository settings:
SUPABASE_PROJECT_ID: Your Supabase project ID (e.g., bgbavxtjlbvgplozizxu)SUPABASE_ACCESS_TOKEN: Supabase access token with read permissionsThe Supabase CLI is included as a dev dependency. Run npm install.
Create .env.local file with SUPABASE_ACCESS_TOKEN=your-access-token-here.
Add secrets to repository:
SUPABASE_PROJECT_IDSUPABASE_ACCESS_TOKENRun npm run types:generate to generate from remote database, npm run types:generate:local for local, and npm run types:check to verify they are up-to-date.
Run npm run types:check. Expected output shows: file path and size, file age (recent), presence of Database/Tables/TablesInsert/TablesUpdate/Json types, and total tables count.
main)Add to .husky/pre-commit to run npm run types:check before each commit.
Add a step to .github/workflows/deploy.yml that runs npm run types:check.
The generated src/integrations/supabase/types.ts file contains a Database type with a public schema holding Tables (each with Row, Insert, Update subtypes), Views, Functions, and Enums. Helper types Tables<T>, TablesInsert<T>, and TablesUpdate<T> are also exported for convenient usage.
Problem: npm run types:generate fails
Solutions:
SUPABASE_ACCESS_TOKEN is setnpx supabase --versionbgbavxtjlbvgplozizxuProblem: Types don't match database schema
Solutions:
npm run types:generate manuallyProblem: Workflow fails to update types
Solutions:
SUPABASE_ACCESS_TOKEN has read permissionsAlways regenerate types after schema changes — run npm run types:generate
Check types before committing — run npm run types:check
Review automated PRs carefully
Keep types in sync
Use generated types in code — import Tables and TablesInsert from @/integrations/supabase/types for type-safe queries