-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server-creation.sql
More file actions
129 lines (111 loc) · 3.47 KB
/
Copy pathtest-server-creation.sql
File metadata and controls
129 lines (111 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
-- Test Server Creation Without Recursion
-- This script tests the server creation process to ensure no recursion issues
-- First, let's check if we have any users
SELECT '=== CHECKING FOR USERS ===' as info;
SELECT
id,
email,
created_at
FROM auth.users
LIMIT 5;
-- Check if we have any profiles
SELECT '=== CHECKING FOR PROFILES ===' as info;
SELECT
id,
username,
display_name,
created_at
FROM profiles
LIMIT 5;
-- Check current server count
SELECT '=== CURRENT SERVERS ===' as info;
SELECT
COUNT(*) as total_servers,
COUNT(CASE WHEN privacy_level = 'public' THEN 1 END) as public_servers,
COUNT(CASE WHEN privacy_level = 'private' THEN 1 END) as private_servers,
COUNT(CASE WHEN privacy_level = 'invite_only' THEN 1 END) as invite_only_servers
FROM servers;
-- Check RLS policies for servers table
SELECT '=== SERVER RLS POLICIES ===' as info;
SELECT
policyname,
cmd,
qual,
with_check
FROM pg_policies
WHERE schemaname = 'public'
AND tablename = 'servers'
ORDER BY policyname;
-- Test manual server creation (this should work without recursion)
SELECT '=== TESTING MANUAL SERVER CREATION ===' as info;
-- Get a test user ID (replace with actual user ID if needed)
DO $$
DECLARE
test_user_id UUID;
new_server_id UUID;
new_channel_id UUID;
BEGIN
-- Get the first user (or you can replace with a specific user ID)
SELECT id INTO test_user_id FROM auth.users LIMIT 1;
IF test_user_id IS NULL THEN
RAISE NOTICE 'No users found in auth.users';
RETURN;
END IF;
RAISE NOTICE 'Testing with user ID: %', test_user_id;
-- Create a test server
INSERT INTO servers (
name,
description,
owner_id,
privacy_level,
invite_code,
is_public
) VALUES (
'Test Server',
'A test server to verify no recursion issues',
test_user_id,
'public',
upper(substring(md5(random()::text) from 1 for 8)),
true
) RETURNING id INTO new_server_id;
RAISE NOTICE 'Server created successfully with ID: %', new_server_id;
-- Create a test channel
INSERT INTO channels (
server_id,
name,
type,
position
) VALUES (
new_server_id,
'general',
'text',
0
) RETURNING id INTO new_channel_id;
RAISE NOTICE 'Channel created successfully with ID: %', new_channel_id;
-- Add user as member (this should work without recursion)
INSERT INTO server_members (
server_id,
user_id
) VALUES (
new_server_id,
test_user_id
);
RAISE NOTICE 'User added as member successfully';
-- Clean up test data
DELETE FROM server_members WHERE server_id = new_server_id;
DELETE FROM channels WHERE server_id = new_server_id;
DELETE FROM servers WHERE id = new_server_id;
RAISE NOTICE 'Test completed successfully - no recursion issues detected!';
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'Error during test: %', SQLERRM;
-- Clean up on error
IF new_server_id IS NOT NULL THEN
DELETE FROM server_members WHERE server_id = new_server_id;
DELETE FROM channels WHERE server_id = new_server_id;
DELETE FROM servers WHERE id = new_server_id;
END IF;
END $$;
-- Show final status
SELECT '=== FINAL STATUS ===' as info;
SELECT 'Server creation test completed. Check the logs above for any errors.' as status;