-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-triggers.js
More file actions
94 lines (78 loc) · 2.88 KB
/
Copy pathcheck-triggers.js
File metadata and controls
94 lines (78 loc) · 2.88 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
// Check what database triggers currently exist
const { createClient } = require('@supabase/supabase-js');
async function checkTriggers() {
console.log('Checking current database triggers...');
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY,
{
auth: {
autoRefreshToken: false,
persistSession: false,
},
}
);
// We can't directly query information_schema through the JS client,
// but we can test if specific operations work to infer trigger status
try {
console.log('1. Testing if problematic triggers still exist...');
// Test 1: Try creating a simple organization (this will fail if triggers exist)
const testOrgName = `Trigger Test ${Date.now()}`;
const testSlug = `trigger-test-${Date.now()}`;
const { data, error } = await supabase
.from('organizations')
.insert({
name: testOrgName,
slug: testSlug,
})
.select()
.single();
if (error) {
if (error.message.includes('organization_id')) {
console.log('❌ Problematic triggers are STILL ACTIVE');
console.log(' Error:', error.message);
console.log(' The database fix was not applied or not effective');
} else {
console.log('❌ Different error (triggers may be fixed):', error.message);
}
} else {
console.log('✅ Organization creation SUCCESSFUL - triggers are fixed!');
console.log(' Created org:', data);
// Clean up
await supabase.from('organizations').delete().eq('id', data.id);
console.log('✅ Test organization cleaned up');
}
// Test 2: Check if we can create users now
console.log('\n2. Testing user creation in public.users...');
const testUserId = '11111111-1111-1111-1111-111111111111';
const testEmail = `trigger-test-${Date.now()}@example.com`;
const { data: userData, error: userError } = await supabase
.from('users')
.insert({
id: testUserId,
email: testEmail,
name: 'Trigger Test User',
})
.select()
.single();
if (userError) {
if (userError.message.includes('organization_id')) {
console.log('❌ User table triggers are STILL ACTIVE');
console.log(' Error:', userError.message);
} else {
console.log('❌ Different user creation error:', userError.message);
}
} else {
console.log('✅ User creation SUCCESSFUL - user triggers are fixed!');
console.log(' Created user:', userData);
// Clean up
await supabase.from('users').delete().eq('id', testUserId);
console.log('✅ Test user cleaned up');
}
} catch (error) {
console.error('General error:', error);
}
}
// Load environment variables
require('dotenv').config({ path: '.env.local' });
checkTriggers();