Skip to content

Commit 396625c

Browse files
committed
test: add reset script to improve dev workflow
1 parent 84685f7 commit 396625c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ help:
1919
@echo " test - Run tests"
2020
@echo " pg_tap - Run pg_tap tests"
2121

22+
# Reset database
23+
.PHONY: reset-database
24+
reset-database:
25+
@echo "Resetting..."
26+
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -p $(PG_PORT) -U $(PG_USER) -d $(PG_DB) -v ON_ERROR_STOP=1 -f $(TEST_DIR)/reset.sql
27+
2228
# Set up Supabase
2329
.PHONY: setup-supabase
2430
setup-supabase:

tests/reset.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- KeyHippo Database Reset Script
2+
-- Drop schemas
3+
DROP TABLE IF EXISTS public.test_accounts CASCADE;
4+
5+
DROP SCHEMA IF EXISTS keyhippo CASCADE;
6+
7+
DROP SCHEMA IF EXISTS keyhippo_internal CASCADE;
8+
9+
DROP SCHEMA IF EXISTS keyhippo_rbac CASCADE;
10+
11+
DROP SCHEMA IF EXISTS keyhippo_impersonation CASCADE;
12+
13+
-- Drop custom types
14+
DROP TYPE IF EXISTS keyhippo.app_permission CASCADE;
15+
16+
DROP TYPE IF EXISTS keyhippo.app_role CASCADE;
17+
18+
-- Delete all rows from auth.users
19+
DELETE FROM auth.users;
20+
21+
-- Drop the trigger on auth.users
22+
DROP TRIGGER IF EXISTS assign_default_role_trigger ON auth.users;
23+
24+
-- Notify PostgREST to reload configuration
25+
NOTIFY pgrst,
26+
'reload config';

0 commit comments

Comments
 (0)