This document explains how to use our database testing tools to ensure data integrity and accessibility.
Testing database access is critical for our application because:
- It ensures our TypeScript types match the actual database schema
- It catches permission issues early
- It prevents bugs when database schema changes
- It verifies all expected columns are accessible
We've created several tools to help test and validate the database:
The tests/supabase-access.test.ts file contains tests that verify we can access every column in every table.
To run these tests:
npm run test:dbThis will:
- Connect to your Supabase database using credentials in
.env.local - Try to query each table
- Verify all columns defined in our types are accessible
The scripts/validate-db-schema.js script checks if our TypeScript types match the actual database schema.
To validate the schema:
npm run validate:dbThis will:
- Extract table and column definitions from our TypeScript types
- Query the actual database schema
- Report any tables or columns that exist in the database but are missing in our types
You should run these tests:
- After making changes to the database schema
- When updating the
lib/supabase.tstype definitions - After a Supabase upgrade or migration
- Before deploying to production
- When experiencing unexpected data access issues
If validate:db reports missing columns:
- Open
lib/supabase.ts - Find the table definition that's missing columns
- Add the missing columns with their appropriate types
If tests report permission errors:
- Check your Supabase API key in
.env.local - Verify Row Level Security (RLS) policies in Supabase
- Make sure your account has proper permissions
Empty tables will show warnings but not errors. If you want to test column access more thoroughly, add some sample data to your tables.
These tests are configured to run automatically in GitHub Actions when:
- The database type definitions change
- The tests themselves change
- A pull request is opened that affects related files
See .github/workflows/database-tests.yml for configuration details.