The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: add database testing guide (#9921)
Han Qiaoef0b8726fe06
diff --git a/apps/reference/docs/guides/cli/testing.mdx b/apps/reference/docs/guides/cli/testing.mdxnew file mode 100644index 00000000000..ce2d1b299a2--- /dev/null+++ b/apps/reference/docs/guides/cli/testing.mdx@@ -0,0 +1,70 @@+---+id: testing+title: Testing Your Database+description: Test your database schema, tables, functions, and policies.+---++import Tabs from '@theme/Tabs'+import TabItem from '@theme/TabItem'++You can use the Supabase CLI to test your database. To get started:++- [Install the Supabase CLI](/docs/guides/cli) on your local machine++## Creating a test++Create a tests folder inside the supabase folder:++```bash+mkdir -p ./supabase/tests/database+```++Create a new file with the `.sql` extension which will contain the test.++```bash+touch ./supabase/tests/database/hello_world.test.sql+```++## Writing tests++All `sql` files use [pgTAP](/docs/guides/database/extensions/pgtap) as the test runner.++Let’s write a simple test to check that our `auth.users` table has an ID column. Open `hello_world.test.sql` and add the following code:++```sql+begin;+select plan(1); -- only one statement to run++SELECT has_column(+ 'auth',+ 'users',+ 'id',+ 'id should exist'+);++select * from finish();+rollback;+```++## Running tests++To run the test, you can use:++```bash+supabase test db+```++This will produce the following output:++```bash+$ supabase test db+supabase/tests/database/hello_world.test.sql .. ok+All tests successful.+Files=1, Tests=1, 1 wallclock secs ( 0.01 usr 0.00 sys + 0.04 cusr 0.02 csys = 0.07 CPU)+Result: PASS+```++## More resource++- [pgTAP extension](https://supabase.com/docs/guides/database/extensions/pgtap)+- Official [pgTAP documentation](https://pgtap.org/)