Skip to content

Commit

Permalink
test: add reset script to improve dev workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
david-r-cox committed Dec 16, 2024
1 parent 84685f7 commit 396625c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ help:
@echo " test - Run tests"
@echo " pg_tap - Run pg_tap tests"

# Reset database
.PHONY: reset-database
reset-database:
@echo "Resetting..."
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

# Set up Supabase
.PHONY: setup-supabase
setup-supabase:
Expand Down
26 changes: 26 additions & 0 deletions tests/reset.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- KeyHippo Database Reset Script
-- Drop schemas
DROP TABLE IF EXISTS public.test_accounts CASCADE;

DROP SCHEMA IF EXISTS keyhippo CASCADE;

DROP SCHEMA IF EXISTS keyhippo_internal CASCADE;

DROP SCHEMA IF EXISTS keyhippo_rbac CASCADE;

DROP SCHEMA IF EXISTS keyhippo_impersonation CASCADE;

-- Drop custom types
DROP TYPE IF EXISTS keyhippo.app_permission CASCADE;

DROP TYPE IF EXISTS keyhippo.app_role CASCADE;

-- Delete all rows from auth.users
DELETE FROM auth.users;

-- Drop the trigger on auth.users
DROP TRIGGER IF EXISTS assign_default_role_trigger ON auth.users;

-- Notify PostgREST to reload configuration
NOTIFY pgrst,
'reload config';

0 comments on commit 396625c

Please sign in to comment.