@pgpm/supabase 0.5.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +2 -1
  2. package/Makefile +2 -3
  3. package/README.md +45 -59
  4. package/deploy/roles/anon.sql +15 -0
  5. package/deploy/schemas/supabase_integration/procedures/pre_request.sql +26 -0
  6. package/deploy/schemas/supabase_integration/schema.sql +9 -0
  7. package/package.json +27 -12
  8. package/pgpm-supabase.control +7 -0
  9. package/pgpm.plan +6 -3
  10. package/revert/roles/anon.sql +7 -0
  11. package/revert/schemas/supabase_integration/procedures/pre_request.sql +7 -0
  12. package/revert/schemas/supabase_integration/schema.sql +7 -0
  13. package/sql/pgpm-supabase--1.0.0.bundle.tar.gz +0 -0
  14. package/sql/pgpm-supabase--1.0.0.sql +32 -0
  15. package/verify/roles/anon.sql +12 -0
  16. package/verify/schemas/supabase_integration/procedures/pre_request.sql +19 -0
  17. package/verify/schemas/supabase_integration/schema.sql +18 -0
  18. package/__tests__/_realtime/_realtime-extensions.test.ts +0 -129
  19. package/__tests__/_realtime/_realtime-schema-migrations.test.ts +0 -160
  20. package/__tests__/_realtime/_realtime-tenants.test.ts +0 -163
  21. package/__tests__/auth/auth.audit-log-entries.test.ts +0 -148
  22. package/__tests__/auth/auth.flow-state.test.ts +0 -114
  23. package/__tests__/auth/auth.identities.test.ts +0 -149
  24. package/__tests__/auth/auth.instances.test.ts +0 -134
  25. package/__tests__/auth/auth.mfa-amr-claims.test.ts +0 -142
  26. package/__tests__/auth/auth.mfa-challenges.test.ts +0 -117
  27. package/__tests__/auth/auth.mfa-factors.test.ts +0 -118
  28. package/__tests__/auth/auth.oauth-authorizations.test.ts +0 -123
  29. package/__tests__/auth/auth.oauth-clients.test.ts +0 -120
  30. package/__tests__/auth/auth.oauth-consents.test.ts +0 -122
  31. package/__tests__/auth/auth.one-time-tokens.test.ts +0 -194
  32. package/__tests__/auth/auth.refresh-tokens.test.ts +0 -134
  33. package/__tests__/auth/auth.saml-providers.test.ts +0 -154
  34. package/__tests__/auth/auth.saml-relay-states.test.ts +0 -145
  35. package/__tests__/auth/auth.schema-migrations.test.ts +0 -131
  36. package/__tests__/auth/auth.sessions.test.ts +0 -140
  37. package/__tests__/auth/auth.sso-domains.test.ts +0 -137
  38. package/__tests__/auth/auth.sso-providers.test.ts +0 -136
  39. package/__tests__/auth/auth.users.test.ts +0 -314
  40. package/__tests__/conditional.test.ts +0 -229
  41. package/__tests__/functions.test.ts +0 -252
  42. package/__tests__/jsonb.test.ts +0 -237
  43. package/__tests__/net/net.http-request-queue.test.ts +0 -159
  44. package/__tests__/net/net.http-response.test.ts +0 -163
  45. package/__tests__/realtime/realtime.messages-2025-10-31.test.ts +0 -168
  46. package/__tests__/realtime/realtime.messages.test.ts +0 -162
  47. package/__tests__/realtime/realtime.schema-migrations.test.ts +0 -139
  48. package/__tests__/realtime/realtime.subscription.test.ts +0 -159
  49. package/__tests__/storage/storage.buckets-analytics.test.ts +0 -134
  50. package/__tests__/storage/storage.buckets.test.ts +0 -146
  51. package/__tests__/storage/storage.iceberg-namespaces.test.ts +0 -132
  52. package/__tests__/storage/storage.iceberg-tables.test.ts +0 -142
  53. package/__tests__/storage/storage.migrations.test.ts +0 -133
  54. package/__tests__/storage/storage.objects.test.ts +0 -160
  55. package/__tests__/storage/storage.prefixes.test.ts +0 -138
  56. package/__tests__/storage/storage.s3-multipart-uploads-parts.test.ts +0 -133
  57. package/__tests__/storage/storage.s3-multipart-uploads.test.ts +0 -128
  58. package/__tests__/supabase-functions/supabase.functions-hooks.test.ts +0 -125
  59. package/__tests__/supabase-functions/supabase.functions-migrations.test.ts +0 -213
  60. package/__tests__/temporal.test.ts +0 -225
  61. package/__tests__/vault-secrets.test.ts +0 -145
  62. package/deploy/LICENSE +0 -9
  63. package/deploy/supabase.sql +0 -2271
  64. package/jest.config.js +0 -15
  65. package/revert/supabase.sql +0 -3
  66. package/sql/supabase--0.0.1.sql +0 -1368
  67. package/src/index.ts +0 -3
  68. package/supabase.control +0 -7
  69. package/verify/supabase.sql +0 -3
@@ -1,142 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
- let testUserId: string | null = null;
7
-
8
- beforeAll(async () => {
9
- ({ pg, db, teardown } = await getConnections());
10
-
11
- // verify storage schema exists
12
- const storageSchemaExists = await pg.any(
13
- `SELECT EXISTS (
14
- SELECT FROM information_schema.schemata
15
- WHERE schema_name = 'storage'
16
- ) as exists`
17
- );
18
- expect(storageSchemaExists[0].exists).toBe(true);
19
-
20
- // grant access to storage schema for testing
21
- await pg.any(
22
- `GRANT USAGE ON SCHEMA storage TO public;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO service_role;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO authenticated;
25
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO anon;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO service_role;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO authenticated;
28
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO anon;`,
29
- []
30
- );
31
-
32
- const u = await pg.one(
33
- `INSERT INTO auth.users (id, email)
34
- VALUES (gen_random_uuid(), $1)
35
- RETURNING id`,
36
- ['storage-iceberg-test@example.com']
37
- );
38
- testUserId = u.id;
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: storage iceberg_tables table access', () => {
54
-
55
- it('should verify iceberg_tables table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'storage' AND table_name = 'iceberg_tables'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can query iceberg_tables', async () => {
71
- db.setContext({ role: 'service_role' });
72
-
73
- // service_role should be able to query iceberg_tables
74
- const tables = await db.any(
75
- `SELECT id, namespace_id, bucket_id, name, location, created_at, updated_at
76
- FROM storage.iceberg_tables
77
- LIMIT 10`
78
- );
79
-
80
- expect(Array.isArray(tables)).toBe(true);
81
- });
82
-
83
- it('should verify table has foreign key to iceberg_namespaces', async () => {
84
- db.setContext({ role: 'service_role' });
85
-
86
- // check for foreign key constraints to iceberg_namespaces
87
- const fks = await db.any(
88
- `SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
89
- FROM information_schema.table_constraints AS tc
90
- JOIN information_schema.constraint_column_usage AS ccu
91
- ON ccu.constraint_name = tc.constraint_name
92
- WHERE tc.constraint_type = 'FOREIGN KEY'
93
- AND tc.table_schema = 'storage'
94
- AND tc.table_name = 'iceberg_tables'
95
- AND ccu.table_name = 'iceberg_namespaces'`
96
- );
97
-
98
- expect(Array.isArray(fks)).toBe(true);
99
- });
100
-
101
- it('should verify authenticated access to iceberg_tables based on rls', async () => {
102
- db.setContext({ role: 'service_role' });
103
- const rlsStatus = await db.any(
104
- `SELECT c.relrowsecurity
105
- FROM pg_class c
106
- JOIN pg_namespace n ON n.oid = c.relnamespace
107
- WHERE n.nspname = 'storage' AND c.relname = 'iceberg_tables'`
108
- );
109
- expect(Array.isArray(rlsStatus)).toBe(true);
110
-
111
- db.setContext({ role: 'authenticated', 'request.jwt.claim.sub': testUserId });
112
- const result = await db.any(`SELECT * FROM storage.iceberg_tables LIMIT 1`);
113
- expect(Array.isArray(result)).toBe(true);
114
- if (rlsStatus[0]?.relrowsecurity === true) {
115
- expect(result.length).toBe(0);
116
- }
117
- });
118
-
119
- it('should verify anon access to iceberg_tables based on rls', async () => {
120
- db.setContext({ role: 'service_role' });
121
- const rlsStatus = await db.any(
122
- `SELECT c.relrowsecurity
123
- FROM pg_class c
124
- JOIN pg_namespace n ON n.oid = c.relnamespace
125
- WHERE n.nspname = 'storage' AND c.relname = 'iceberg_tables'`
126
- );
127
-
128
- // clear context to anon role
129
- db.clearContext();
130
-
131
- // anon should not be able to access iceberg_tables (rls blocks)
132
- const result = await db.any(
133
- `SELECT * FROM storage.iceberg_tables LIMIT 1`
134
- );
135
-
136
- expect(Array.isArray(result)).toBe(true);
137
- if (rlsStatus[0]?.relrowsecurity === true) {
138
- expect(result.length).toBe(0);
139
- }
140
- });
141
- });
142
-
@@ -1,133 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify storage schema exists
11
- const storageSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'storage'
15
- ) as exists`
16
- );
17
- expect(storageSchemaExists[0].exists).toBe(true);
18
-
19
- // grant access to storage schema for testing
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA storage TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO authenticated;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO anon;`,
28
- []
29
- );
30
-
31
- // assert storage.migrations exists
32
- const exists = await pg.any(
33
- `SELECT EXISTS (
34
- SELECT FROM information_schema.tables
35
- WHERE table_schema = 'storage' AND table_name = 'migrations'
36
- ) as exists`
37
- );
38
- expect(exists[0].exists).toBe(true);
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: storage migrations table access', () => {
54
-
55
- it('should verify migrations table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'storage' AND table_name = 'migrations'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can read migrations', async () => {
71
- db.setContext({ role: 'service_role' });
72
-
73
- // service_role should be able to query migrations
74
- const migrations = await db.any(
75
- `SELECT id, name, hash, executed_at
76
- FROM storage.migrations
77
- ORDER BY executed_at DESC
78
- LIMIT 10`
79
- );
80
-
81
- expect(Array.isArray(migrations)).toBe(true);
82
- });
83
-
84
- it('should verify table has primary key on id', async () => {
85
- db.setContext({ role: 'service_role' });
86
-
87
- // check for primary key constraint
88
- const pk = await db.any(
89
- `SELECT constraint_name
90
- FROM information_schema.table_constraints
91
- WHERE table_schema = 'storage' AND table_name = 'migrations'
92
- AND constraint_type = 'PRIMARY KEY'`
93
- );
94
-
95
- expect(Array.isArray(pk)).toBe(true);
96
- if (pk.length > 0) {
97
- expect(pk[0].constraint_name).toBeDefined();
98
- }
99
- });
100
-
101
- it('should verify table has unique constraint on name', async () => {
102
- db.setContext({ role: 'service_role' });
103
-
104
- // check for unique constraints
105
- const unique = await db.any(
106
- `SELECT constraint_name
107
- FROM information_schema.table_constraints
108
- WHERE table_schema = 'storage' AND table_name = 'migrations'
109
- AND constraint_type = 'UNIQUE'`
110
- );
111
-
112
- expect(Array.isArray(unique)).toBe(true);
113
- });
114
-
115
- it('should verify anon access to migrations based on rls', async () => {
116
- db.setContext({ role: 'service_role' });
117
- const rlsStatus = await db.any(
118
- `SELECT c.relrowsecurity
119
- FROM pg_class c
120
- JOIN pg_namespace n ON n.oid = c.relnamespace
121
- WHERE n.nspname = 'storage' AND c.relname = 'migrations'`
122
- );
123
- expect(Array.isArray(rlsStatus)).toBe(true);
124
-
125
- db.clearContext();
126
- const result = await db.any(`SELECT * FROM storage.migrations LIMIT 1`);
127
- expect(Array.isArray(result)).toBe(true);
128
- if (rlsStatus[0]?.relrowsecurity === true) {
129
- expect(result.length).toBe(0);
130
- }
131
- });
132
- });
133
-
@@ -1,160 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify storage schema exists
11
- const storageSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'storage'
15
- ) as exists`
16
- );
17
- expect(storageSchemaExists[0].exists).toBe(true);
18
-
19
- // grant access to storage schema for testing
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA storage TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO anon;`,
27
- []
28
- );
29
-
30
- // assert storage.objects exists
31
- const exists = await pg.any(
32
- `SELECT EXISTS (
33
- SELECT FROM information_schema.tables
34
- WHERE table_schema = 'storage' AND table_name = 'objects'
35
- ) as exists`
36
- );
37
- expect(exists[0].exists).toBe(true);
38
- });
39
-
40
- afterAll(async () => {
41
- await teardown();
42
- });
43
-
44
- beforeEach(async () => {
45
- await db.beforeEach();
46
- });
47
-
48
- afterEach(async () => {
49
- await db.afterEach();
50
- });
51
-
52
- describe('tutorial: storage objects table access with rls', () => {
53
-
54
- it('should verify objects table exists', async () => {
55
- db.setContext({ role: 'service_role' });
56
- const exists = await db.any(
57
- `SELECT EXISTS (
58
- SELECT FROM information_schema.tables
59
- WHERE table_schema = 'storage' AND table_name = 'objects'
60
- ) as exists`
61
- );
62
- expect(Array.isArray(exists)).toBe(true);
63
- expect(exists[0].exists).toBe(true);
64
- });
65
-
66
- it('should verify rls is enabled on objects table', async () => {
67
- db.setContext({ role: 'service_role' });
68
-
69
- const rlsStatus = await db.any(
70
- `SELECT c.relrowsecurity
71
- FROM pg_class c
72
- JOIN pg_namespace n ON n.oid = c.relnamespace
73
- WHERE n.nspname = 'storage' AND c.relname = 'objects'`
74
- );
75
-
76
- expect(Array.isArray(rlsStatus)).toBe(true);
77
- if (rlsStatus.length > 0) {
78
- expect(typeof rlsStatus[0].relrowsecurity).toBe('boolean');
79
- }
80
- });
81
-
82
- it('should verify service_role can read objects', async () => {
83
- db.setContext({ role: 'service_role' });
84
-
85
- const objects = await db.any(
86
- `SELECT id, bucket_id, name, owner, created_at
87
- FROM storage.objects
88
- LIMIT 10`
89
- );
90
-
91
- expect(Array.isArray(objects)).toBe(true);
92
- });
93
-
94
- it('should verify table has primary key on id', async () => {
95
- db.setContext({ role: 'service_role' });
96
-
97
- const pk = await db.any(
98
- `SELECT constraint_name
99
- FROM information_schema.table_constraints
100
- WHERE table_schema = 'storage' AND table_name = 'objects'
101
- AND constraint_type = 'PRIMARY KEY'`
102
- );
103
-
104
- expect(Array.isArray(pk)).toBe(true);
105
- if (pk.length > 0) {
106
- expect(pk[0].constraint_name).toBeDefined();
107
- }
108
- });
109
-
110
- it('should verify table has unique index on bucket_id and name', async () => {
111
- db.setContext({ role: 'service_role' });
112
-
113
- const indexes = await db.any(
114
- `SELECT indexname
115
- FROM pg_indexes
116
- WHERE schemaname = 'storage' AND tablename = 'objects'
117
- AND indexname = 'bucketid_objname'`
118
- );
119
-
120
- expect(Array.isArray(indexes)).toBe(true);
121
- });
122
-
123
- it('should verify table has foreign key to buckets', async () => {
124
- db.setContext({ role: 'service_role' });
125
-
126
- const fks = await db.any(
127
- `SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
128
- FROM information_schema.table_constraints AS tc
129
- JOIN information_schema.constraint_column_usage AS ccu
130
- ON ccu.constraint_name = tc.constraint_name
131
- WHERE tc.constraint_type = 'FOREIGN KEY'
132
- AND tc.table_schema = 'storage'
133
- AND tc.table_name = 'objects'
134
- AND ccu.table_name = 'buckets'`
135
- );
136
-
137
- expect(Array.isArray(fks)).toBe(true);
138
- });
139
-
140
- it('should verify anon access to objects based on rls', async () => {
141
- // check rls status
142
- db.setContext({ role: 'service_role' });
143
- const rlsStatus = await db.any(
144
- `SELECT c.relrowsecurity
145
- FROM pg_class c
146
- JOIN pg_namespace n ON n.oid = c.relnamespace
147
- WHERE n.nspname = 'storage' AND c.relname = 'objects'`
148
- );
149
- expect(Array.isArray(rlsStatus)).toBe(true);
150
- expect(rlsStatus.length).toBeGreaterThan(0);
151
-
152
- db.clearContext();
153
- const result = await db.any(`SELECT * FROM storage.objects LIMIT 1`);
154
- expect(Array.isArray(result)).toBe(true);
155
- if (rlsStatus[0].relrowsecurity === true) {
156
- expect(result.length).toBe(0);
157
- }
158
- });
159
- });
160
-
@@ -1,138 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
- let testUserId: string | null = null;
7
-
8
- beforeAll(async () => {
9
- ({ pg, db, teardown } = await getConnections());
10
-
11
- // verify storage schema exists
12
- const storageSchemaExists = await pg.any(
13
- `SELECT EXISTS (
14
- SELECT FROM information_schema.schemata
15
- WHERE schema_name = 'storage'
16
- ) as exists`
17
- );
18
- expect(storageSchemaExists[0].exists).toBe(true);
19
-
20
- // grant access to storage schema for testing
21
- await pg.any(
22
- `GRANT USAGE ON SCHEMA storage TO public;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO service_role;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO authenticated;
25
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO anon;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO service_role;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO authenticated;
28
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO anon;`,
29
- []
30
- );
31
-
32
- // ensure test user exists for authenticated context
33
- const u = await pg.one(
34
- `INSERT INTO auth.users (id, email)
35
- VALUES (gen_random_uuid(), $1)
36
- RETURNING id`,
37
- ['storage-prefix-test@example.com']
38
- );
39
- testUserId = u.id;
40
- });
41
-
42
- afterAll(async () => {
43
- await teardown();
44
- });
45
-
46
- beforeEach(async () => {
47
- await db.beforeEach();
48
- });
49
-
50
- afterEach(async () => {
51
- await db.afterEach();
52
- });
53
-
54
- describe('tutorial: storage prefixes table access', () => {
55
-
56
- it('should verify prefixes table exists', async () => {
57
- db.setContext({ role: 'service_role' });
58
-
59
- // verify table exists in information schema
60
- const exists = await db.any(
61
- `SELECT EXISTS (
62
- SELECT FROM information_schema.tables
63
- WHERE table_schema = 'storage' AND table_name = 'prefixes'
64
- ) as exists`
65
- );
66
-
67
- expect(Array.isArray(exists)).toBe(true);
68
- expect(exists[0].exists).toBe(true);
69
- });
70
-
71
- it('should verify service_role can query prefixes', async () => {
72
- db.setContext({ role: 'service_role' });
73
-
74
- // service_role should be able to query prefixes
75
- const prefixes = await db.any(
76
- `SELECT bucket_id, created_at
77
- FROM storage.prefixes
78
- LIMIT 10`
79
- );
80
-
81
- expect(Array.isArray(prefixes)).toBe(true);
82
- });
83
-
84
- it('should verify table has proper structure', async () => {
85
- db.setContext({ role: 'service_role' });
86
-
87
- // query table column structure
88
- const columns = await db.any(
89
- `SELECT column_name
90
- FROM information_schema.columns
91
- WHERE table_schema = 'storage' AND table_name = 'prefixes'
92
- ORDER BY ordinal_position`
93
- );
94
-
95
- expect(Array.isArray(columns)).toBe(true);
96
- });
97
-
98
- it('should verify authenticated access to prefixes based on rls', async () => {
99
- // rls status
100
- db.setContext({ role: 'service_role' });
101
- const rlsStatus = await db.any(
102
- `SELECT c.relrowsecurity
103
- FROM pg_class c
104
- JOIN pg_namespace n ON n.oid = c.relnamespace
105
- WHERE n.nspname = 'storage' AND c.relname = 'prefixes'`
106
- );
107
- expect(Array.isArray(rlsStatus)).toBe(true);
108
-
109
- // set context to authenticated user
110
- db.setContext({
111
- role: 'authenticated',
112
- 'request.jwt.claim.sub': testUserId
113
- });
114
- const result = await db.any(`SELECT * FROM storage.prefixes LIMIT 1`);
115
- expect(Array.isArray(result)).toBe(true);
116
- if (rlsStatus[0]?.relrowsecurity === true) {
117
- expect(result.length).toBe(0);
118
- }
119
- });
120
-
121
- it('should verify anon access to prefixes based on rls', async () => {
122
- db.setContext({ role: 'service_role' });
123
- const rlsStatus = await db.any(
124
- `SELECT c.relrowsecurity
125
- FROM pg_class c
126
- JOIN pg_namespace n ON n.oid = c.relnamespace
127
- WHERE n.nspname = 'storage' AND c.relname = 'prefixes'`
128
- );
129
-
130
- db.clearContext();
131
- const result = await db.any(`SELECT * FROM storage.prefixes LIMIT 1`);
132
- expect(Array.isArray(result)).toBe(true);
133
- if (rlsStatus[0]?.relrowsecurity === true) {
134
- expect(result.length).toBe(0);
135
- }
136
- });
137
- });
138
-
@@ -1,133 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
- let testUserId: string | null = null;
7
-
8
- beforeAll(async () => {
9
- ({ pg, db, teardown } = await getConnections());
10
-
11
- // verify storage schema exists
12
- const storageSchemaExists = await pg.any(
13
- `SELECT EXISTS (
14
- SELECT FROM information_schema.schemata
15
- WHERE schema_name = 'storage'
16
- ) as exists`
17
- );
18
- expect(storageSchemaExists[0].exists).toBe(true);
19
-
20
- // grant access to storage schema for testing
21
- await pg.any(
22
- `GRANT USAGE ON SCHEMA storage TO public;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO service_role;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO authenticated;
25
- GRANT SELECT ON ALL TABLES IN SCHEMA storage TO anon;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO service_role;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO authenticated;
28
- ALTER DEFAULT PRIVILEGES IN SCHEMA storage GRANT SELECT ON TABLES TO anon;`,
29
- []
30
- );
31
-
32
- // create a test user for authenticated context
33
- const u = await pg.one(
34
- `INSERT INTO auth.users (id, email)
35
- VALUES (gen_random_uuid(), $1)
36
- RETURNING id`,
37
- ['storage-parts-test@example.com']
38
- );
39
- testUserId = u.id;
40
- });
41
-
42
- afterAll(async () => {
43
- await teardown();
44
- });
45
-
46
- beforeEach(async () => {
47
- await db.beforeEach();
48
- });
49
-
50
- afterEach(async () => {
51
- await db.afterEach();
52
- });
53
-
54
- describe('tutorial: storage prefixes table access (renamed scenario)', () => {
55
-
56
- it('should verify prefixes table exists', async () => {
57
- db.setContext({ role: 'service_role' });
58
-
59
- // verify table exists in information schema
60
- const exists = await db.any(
61
- `SELECT EXISTS (
62
- SELECT FROM information_schema.tables
63
- WHERE table_schema = 'storage' AND table_name = 'prefixes'
64
- ) as exists`
65
- );
66
-
67
- expect(Array.isArray(exists)).toBe(true);
68
- expect(exists[0].exists).toBe(true);
69
- });
70
-
71
- it('should verify service_role can query prefixes', async () => {
72
- db.setContext({ role: 'service_role' });
73
- // service_role should be able to query prefixes
74
- const rows = await db.any(
75
- `SELECT bucket_id, name, level, created_at, updated_at
76
- FROM storage.prefixes
77
- LIMIT 10`
78
- );
79
- expect(Array.isArray(rows)).toBe(true);
80
- });
81
-
82
- it('should verify table has foreign key to buckets', async () => {
83
- db.setContext({ role: 'service_role' });
84
- // check for foreign key constraints to buckets
85
- const fks = await db.any(
86
- `SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
87
- FROM information_schema.table_constraints AS tc
88
- JOIN information_schema.constraint_column_usage AS ccu
89
- ON ccu.constraint_name = tc.constraint_name
90
- WHERE tc.constraint_type = 'FOREIGN KEY'
91
- AND tc.table_schema = 'storage'
92
- AND tc.table_name = 'prefixes'
93
- AND ccu.table_name = 'buckets'`
94
- );
95
- expect(Array.isArray(fks)).toBe(true);
96
- });
97
-
98
- it('should verify authenticated access to prefixes based on rls', async () => {
99
- db.setContext({ role: 'service_role' });
100
- const rlsStatus = await db.any(
101
- `SELECT c.relrowsecurity
102
- FROM pg_class c
103
- JOIN pg_namespace n ON n.oid = c.relnamespace
104
- WHERE n.nspname = 'storage' AND c.relname = 'prefixes'`
105
- );
106
- expect(Array.isArray(rlsStatus)).toBe(true);
107
-
108
- db.setContext({ role: 'authenticated', 'request.jwt.claim.sub': testUserId });
109
- const result = await db.any(`SELECT * FROM storage.prefixes LIMIT 1`);
110
- expect(Array.isArray(result)).toBe(true);
111
- if (rlsStatus[0]?.relrowsecurity === true) {
112
- expect(result.length).toBe(0);
113
- }
114
- });
115
-
116
- it('should verify anon access to prefixes based on rls', async () => {
117
- db.setContext({ role: 'service_role' });
118
- const rlsStatus = await db.any(
119
- `SELECT c.relrowsecurity
120
- FROM pg_class c
121
- JOIN pg_namespace n ON n.oid = c.relnamespace
122
- WHERE n.nspname = 'storage' AND c.relname = 'prefixes'`
123
- );
124
-
125
- db.clearContext();
126
- const result = await db.any(`SELECT * FROM storage.prefixes LIMIT 1`);
127
- expect(Array.isArray(result)).toBe(true);
128
- if (rlsStatus[0]?.relrowsecurity === true) {
129
- expect(result.length).toBe(0);
130
- }
131
- });
132
- });
133
-