This directory contains database tests using pgTAP (PostgreSQL Testing Framework).
Database tests verify:
- Schema structure (tables, columns, types, constraints)
- Row Level Security (RLS) policies
- Database triggers
- Database functions
# From project root
yarn test:db
# Or directly
supabase test dbsupabase test db --file supabase/tests/database/schema.test.sql- Supabase CLI must be installed (v1.11.4+)
- Local Supabase must be running (
yarn supabase:start)
Tests database schema:
- Table existence
- Column existence and types
- Column constraints (NOT NULL, etc.)
- Indexes
Tests Row Level Security policies:
- Policy existence
- Policy roles (public, authenticated)
- Policy operations (SELECT, INSERT, UPDATE, DELETE)
Tests database triggers:
- Trigger existence
- Trigger functions
- Trigger timing (BEFORE, AFTER)
- Trigger events (INSERT, UPDATE, DELETE)
Tests database functions:
- Function existence
- Function return types
- Function language
- Function behavior
All tests use pgTAP syntax:
BEGIN;
SELECT plan(1); -- Number of tests
-- Your tests here
SELECT has_table('public', 'users', 'users table should exist');
SELECT * FROM finish();
ROLLBACK;has_table(schema, table, description)- Check table existshas_column(schema, table, column, description)- Check column existscol_type_is(schema, table, column, type, description)- Check column typehas_index(schema, table, index, description)- Check index existshas_policy(schema, table, policy, description)- Check RLS policy existshas_trigger(schema, table, trigger, description)- Check trigger existshas_function(schema, function, args, description)- Check function exists
BEGIN;
SELECT plan(3);
-- Test table exists
SELECT has_table('public', 'users', 'users table should exist');
-- Test column exists
SELECT has_column('public', 'users', 'id', 'id column should exist');
-- Test column type
SELECT col_type_is('public', 'users', 'id', 'uuid', 'id should be UUID type');
SELECT * FROM finish();
ROLLBACK;