Skip to content

Commit eb3349d

Browse files
committed
docs: add --use-shadow-db documentation to test db command
Document the --use-shadow-db flag in the CLI man page with usage details, shadow port config, and CI guidance. Add a shadow-db example to examples.yaml and fix the stale shadow_port comment in testdata/config.toml to match the production template.
1 parent 99b5c62 commit eb3349d

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

docs/supabase/test/db.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@ Requires the local development stack to be started by running `supabase start`.
77
Runs `pg_prove` in a container with unit test files volume mounted from `supabase/tests` directory. The test file can be suffixed by either `.sql` or `.pg` extension.
88

99
Since each test is wrapped in its own transaction, it will be individually rolled back regardless of success or failure.
10+
11+
## Running tests against a shadow database
12+
13+
Pass `--use-shadow-db` to run tests against an ephemeral shadow database instead of the local dev database. When this flag is set, the CLI:
14+
15+
1. Spins up a temporary Postgres container
16+
2. Replays all local migrations from `supabase/migrations`
17+
3. Runs the pgTAP tests against this clean database
18+
4. Destroys the container when finished
19+
20+
Your local dev database is never touched, making this ideal for CI pipelines and ensuring tests always run against a clean, migration-defined schema.
21+
22+
The shadow database uses the `shadow_port` configured in `config.toml` (default `54320`) — the same port used by `db diff`. Because they share this port, you cannot run `db diff` and `db test --use-shadow-db` simultaneously.

docs/templates/examples.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ supabase-test-db:
295295
All tests successful.
296296
Files=2, Tests=2, 6 wallclock secs ( 0.03 usr 0.01 sys + 0.05 cusr 0.02 csys = 0.11 CPU)
297297
Result: PASS
298+
- id: shadow-db
299+
name: Run tests against an isolated shadow database
300+
code: supabase test db --use-shadow-db
301+
response: |
302+
Creating shadow database...
303+
Applying migration 20220810154537_create_employees_table.sql...
304+
/tmp/supabase/tests/nested/order_test.pg .. ok
305+
/tmp/supabase/tests/pet_test.sql .......... ok
306+
All tests successful.
307+
Files=2, Tests=2, 6 wallclock secs ( 0.03 usr 0.01 sys + 0.05 cusr 0.02 csys = 0.11 CPU)
308+
Result: PASS
298309
# TODO: use actual cli response for sso commands
299310
supabase-sso-show:
300311
- id: basic-usage

pkg/config/testdata/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ key_path = "../certs/my-key.pem"
2727
[db]
2828
# Port to use for the local database URL.
2929
port = 54322
30-
# Port used by db diff command to initialize the shadow database.
30+
# Port used by db diff and test db commands to initialize the shadow database.
3131
shadow_port = 54320
3232
# Maximum amount of time to wait for health check when starting the local database.
3333
health_timeout = "2m"

0 commit comments

Comments
 (0)