new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Supabase · Database · all subjects

testing

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Two approaches to testing Supabase databases

There are two main approaches to testing Supabase databases: (1) Write tests using a Supabase client instance in your application's programming language with your favorite testing framework, interfacing with Supabase the same way you use it in production code. (2) Test through the Supabase CLI with a lower-level approach where you write tests directly in SQL.

Supabase CLI test folder structure

Create a tests folder inside the supabase folder with the path ./supabase/tests/database to organize database tests. Test files should use the .sql extension.

SQL tests use pgTAP as the test runner

All SQL test files in Supabase use pgTAP as the test runner. You write SQL test files with the .sql extension in the ./supabase/tests/database folder.

Running Supabase database tests

Run tests using the command 'supabase test db' from the command line. This executes all SQL test files in the ./supabase/tests/database folder and reports results.

pgTAP test structure with begin, plan, and finish

SQL tests using pgTAP follow this structure: begin a transaction, use select plan(N) to declare the number of test statements, write test assertions, call select * from finish() to complete the test, and rollback the transaction.

Testing column existence with pgTAP

Use the pgTAP function has_column(schema_name, table_name, column_name, description) to test that a column exists in a table. For example: SELECT has_column('auth', 'users', 'id', 'id should exist');

Minimum Supabase CLI version for testing

The minimum required version of the Supabase CLI to run database tests is v1.11.4.

Testing RLS policies is possible with pgTAP

RLS policies can be tested using pgTAP tests through the Supabase CLI. Tests can verify that RLS policies are correctly applied and that queries return expected data.

Give your agent this brain