Skip to content

Commit 4671f75

Browse files
committed
clean up deploy scripts
1 parent fff8d8e commit 4671f75

File tree

2 files changed

+44
-50
lines changed

2 files changed

+44
-50
lines changed

packages/hello-world/revert/rls-demo.sql

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
-- Revert: rls-demo from pg
22

33
-- Drop triggers
4-
DROP TRIGGER IF EXISTS update_products_updated_at ON rls_test.products;
5-
DROP TRIGGER IF EXISTS update_users_updated_at ON rls_test.user_profiles;
4+
DROP TRIGGER IF EXISTS update_users_updated_at ON rls_test.pets;
65

76
-- Drop trigger function
87
DROP FUNCTION IF EXISTS rls_test.update_updated_at_column();
98

109
-- Drop indexes
11-
DROP INDEX IF EXISTS idx_users_email;
12-
DROP INDEX IF EXISTS idx_products_owner_id;
10+
DROP INDEX IF EXISTS idx_users_user_id;
1311

14-
-- Drop policies
15-
DROP POLICY IF EXISTS "Users can delete own products" ON rls_test.products;
16-
DROP POLICY IF EXISTS "Users can update own products" ON rls_test.products;
17-
DROP POLICY IF EXISTS "Users can insert own products" ON rls_test.products;
18-
DROP POLICY IF EXISTS "Users can view own products" ON rls_test.products;
12+
-- Revoke permissions from service role
13+
REVOKE ALL ON rls_test.pets FROM service_role;
14+
REVOKE USAGE ON SCHEMA rls_test FROM service_role;
15+
16+
-- Revoke permissions from authenticated users
17+
REVOKE ALL ON rls_test.pets FROM authenticated;
18+
REVOKE USAGE ON SCHEMA rls_test FROM authenticated;
1919

20-
DROP POLICY IF EXISTS "Users can delete own data" ON rls_test.user_profiles;
21-
DROP POLICY IF EXISTS "Users can insert own data" ON rls_test.user_profiles;
22-
DROP POLICY IF EXISTS "Users can update own data" ON rls_test.user_profiles;
23-
DROP POLICY IF EXISTS "Users can view own data" ON rls_test.user_profiles;
20+
-- Revoke permissions from anon users
21+
REVOKE ALL ON rls_test.pets FROM anon;
22+
REVOKE USAGE ON SCHEMA rls_test FROM anon;
23+
24+
-- Drop policies
25+
DROP POLICY IF EXISTS "Users can delete own data" ON rls_test.pets;
26+
DROP POLICY IF EXISTS "Users can insert own data" ON rls_test.pets;
27+
DROP POLICY IF EXISTS "Users can update own data" ON rls_test.pets;
28+
DROP POLICY IF EXISTS "Users can view own data" ON rls_test.pets;
2429

2530
-- Drop tables
26-
DROP TABLE IF EXISTS rls_test.products;
27-
DROP TABLE IF EXISTS rls_test.user_profiles;
31+
DROP TABLE IF EXISTS rls_test.pets;
2832

2933
-- Drop schemas
3034
DROP SCHEMA IF EXISTS rls_test;
31-
DROP SCHEMA IF EXISTS auth;

packages/hello-world/verify/rls-demo.sql

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,68 @@
33
-- Verify schema exists
44
SELECT 1 FROM information_schema.schemata WHERE schema_name = 'rls_test';
55

6-
-- Verify users table exists with correct structure
6+
-- Verify pets table exists with correct structure
77
SELECT 1 FROM information_schema.tables
8-
WHERE table_schema = 'rls_test' AND table_name = 'users';
8+
WHERE table_schema = 'rls_test' AND table_name = 'pets';
99

1010
SELECT 1 FROM information_schema.columns
11-
WHERE table_schema = 'rls_test' AND table_name = 'users' AND column_name = 'id';
11+
WHERE table_schema = 'rls_test' AND table_name = 'pets' AND column_name = 'id';
1212

1313
SELECT 1 FROM information_schema.columns
14-
WHERE table_schema = 'rls_test' AND table_name = 'users' AND column_name = 'email';
14+
WHERE table_schema = 'rls_test' AND table_name = 'pets' AND column_name = 'user_id';
1515

1616
SELECT 1 FROM information_schema.columns
17-
WHERE table_schema = 'rls_test' AND table_name = 'users' AND column_name = 'name';
18-
19-
-- Verify products table exists with correct structure
20-
SELECT 1 FROM information_schema.tables
21-
WHERE table_schema = 'rls_test' AND table_name = 'products';
17+
WHERE table_schema = 'rls_test' AND table_name = 'pets' AND column_name = 'name';
2218

2319
SELECT 1 FROM information_schema.columns
24-
WHERE table_schema = 'rls_test' AND table_name = 'products' AND column_name = 'id';
20+
WHERE table_schema = 'rls_test' AND table_name = 'pets' AND column_name = 'breed';
2521

2622
SELECT 1 FROM information_schema.columns
27-
WHERE table_schema = 'rls_test' AND table_name = 'products' AND column_name = 'owner_id';
23+
WHERE table_schema = 'rls_test' AND table_name = 'pets' AND column_name = 'created_at';
2824

2925
SELECT 1 FROM information_schema.columns
30-
WHERE table_schema = 'rls_test' AND table_name = 'products' AND column_name = 'name';
26+
WHERE table_schema = 'rls_test' AND table_name = 'pets' AND column_name = 'updated_at';
3127

3228
-- Verify foreign key constraint
3329
SELECT 1 FROM information_schema.table_constraints
3430
WHERE table_schema = 'rls_test'
35-
AND table_name = 'products'
31+
AND table_name = 'pets'
3632
AND constraint_type = 'FOREIGN KEY'
37-
AND constraint_name LIKE '%owner_id%';
33+
AND constraint_name LIKE '%user_id%';
3834

3935
-- Verify RLS is enabled
4036
SELECT 1 FROM pg_class c
4137
JOIN pg_namespace n ON n.oid = c.relnamespace
4238
WHERE n.nspname = 'rls_test'
43-
AND c.relname = 'users'
44-
AND c.relrowsecurity = true;
45-
46-
SELECT 1 FROM pg_class c
47-
JOIN pg_namespace n ON n.oid = c.relnamespace
48-
WHERE n.nspname = 'rls_test'
49-
AND c.relname = 'products'
39+
AND c.relname = 'pets'
5040
AND c.relrowsecurity = true;
5141

5242
-- Verify policies exist
5343
SELECT 1 FROM pg_policies
5444
WHERE schemaname = 'rls_test'
55-
AND tablename = 'users'
45+
AND tablename = 'pets'
5646
AND policyname = 'Users can view own data';
5747

5848
SELECT 1 FROM pg_policies
5949
WHERE schemaname = 'rls_test'
60-
AND tablename = 'products'
61-
AND policyname = 'Users can view own products';
50+
AND tablename = 'pets'
51+
AND policyname = 'Users can update own data';
6252

63-
-- Verify indexes exist
64-
SELECT 1 FROM pg_indexes
53+
SELECT 1 FROM pg_policies
54+
WHERE schemaname = 'rls_test'
55+
AND tablename = 'pets'
56+
AND policyname = 'Users can insert own data';
57+
58+
SELECT 1 FROM pg_policies
6559
WHERE schemaname = 'rls_test'
66-
AND tablename = 'products'
67-
AND indexname = 'idx_products_owner_id';
60+
AND tablename = 'pets'
61+
AND policyname = 'Users can delete own data';
6862

63+
-- Verify indexes exist
6964
SELECT 1 FROM pg_indexes
7065
WHERE schemaname = 'rls_test'
71-
AND tablename = 'users'
72-
AND indexname = 'idx_users_email';
66+
AND tablename = 'pets'
67+
AND indexname = 'idx_users_user_id';
7368

7469
-- Verify trigger function exists
7570
SELECT 1 FROM information_schema.routines
@@ -80,7 +75,3 @@ AND routine_name = 'update_updated_at_column';
8075
SELECT 1 FROM information_schema.triggers
8176
WHERE trigger_schema = 'rls_test'
8277
AND trigger_name = 'update_users_updated_at';
83-
84-
SELECT 1 FROM information_schema.triggers
85-
WHERE trigger_schema = 'rls_test'
86-
AND trigger_name = 'update_products_updated_at';

0 commit comments

Comments
 (0)