-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_supabase_connection.sh
More file actions
executable file
·164 lines (141 loc) · 4.97 KB
/
test_supabase_connection.sh
File metadata and controls
executable file
·164 lines (141 loc) · 4.97 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Test Supabase Connection for OpenJobs
# This script tests read/write access to the new cloud Supabase instance
echo "🧪 Testing OpenJobs → Supabase Connection"
echo "=========================================="
echo ""
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
else
echo "❌ .env file not found!"
exit 1
fi
# Check required env vars
if [ -z "$SUPABASE_URL" ] || [ -z "$SUPABASE_ANON_KEY" ]; then
echo "❌ Missing SUPABASE_URL or SUPABASE_ANON_KEY in .env"
exit 1
fi
echo "📍 Supabase URL: $SUPABASE_URL"
echo ""
# Test 1: Health Check
echo "Test 1: Health Check"
echo "--------------------"
response=$(curl -s -o /dev/null -w "%{http_code}" \
-H "apikey: $SUPABASE_ANON_KEY" \
"${SUPABASE_URL}/rest/v1/")
if [ "$response" = "200" ]; then
echo "✅ Supabase is reachable (HTTP $response)"
else
echo "❌ Supabase health check failed (HTTP $response)"
exit 1
fi
echo ""
# Test 2: Read from job_posts table
echo "Test 2: Read Access (job_posts)"
echo "-------------------------------"
response=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-H "apikey: $SUPABASE_ANON_KEY" \
-H "Authorization: Bearer $SUPABASE_ANON_KEY" \
"${SUPABASE_URL}/rest/v1/job_posts?select=id,title&limit=5")
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d: -f2)
body=$(echo "$response" | sed '/HTTP_CODE:/d')
if [ "$http_code" = "200" ]; then
echo "✅ Can read from job_posts table"
echo "📊 Sample data:"
echo "$body" | jq -r '.[] | " - \(.id): \(.title)"' 2>/dev/null || echo "$body"
else
echo "❌ Failed to read from job_posts (HTTP $http_code)"
echo "Response: $body"
fi
echo ""
# Test 3: Write to job_posts table (test job)
echo "Test 3: Write Access (job_posts)"
echo "--------------------------------"
test_id="test-$(date +%s)"
test_job='{
"id": "'$test_id'",
"title": "Test Job - Connection Check",
"company": "OpenJobs Test",
"description": "This is a test job to verify write access",
"location": "Test Location",
"is_active": false
}'
response=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-X POST \
-H "apikey: $SUPABASE_ANON_KEY" \
-H "Authorization: Bearer $SUPABASE_ANON_KEY" \
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d "$test_job" \
"${SUPABASE_URL}/rest/v1/job_posts")
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d: -f2)
body=$(echo "$response" | sed '/HTTP_CODE:/d')
if [ "$http_code" = "201" ]; then
echo "✅ Can write to job_posts table"
echo "📝 Created test job: $test_id"
else
echo "❌ Failed to write to job_posts (HTTP $http_code)"
echo "Response: $body"
fi
echo ""
# Test 4: Update test job
echo "Test 4: Update Access (job_posts)"
echo "---------------------------------"
response=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-X PATCH \
-H "apikey: $SUPABASE_ANON_KEY" \
-H "Authorization: Bearer $SUPABASE_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"description": "Updated test description"}' \
"${SUPABASE_URL}/rest/v1/job_posts?id=eq.$test_id")
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d: -f2)
if [ "$http_code" = "200" ] || [ "$http_code" = "204" ]; then
echo "✅ Can update job_posts table"
else
echo "❌ Failed to update job_posts (HTTP $http_code)"
fi
echo ""
# Test 5: Delete test job (cleanup)
echo "Test 5: Cleanup (delete test job)"
echo "---------------------------------"
response=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-X DELETE \
-H "apikey: $SUPABASE_ANON_KEY" \
-H "Authorization: Bearer $SUPABASE_ANON_KEY" \
"${SUPABASE_URL}/rest/v1/job_posts?id=eq.$test_id")
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d: -f2)
if [ "$http_code" = "200" ] || [ "$http_code" = "204" ]; then
echo "✅ Can delete from job_posts table"
echo "🧹 Test job cleaned up"
else
echo "⚠️ Could not delete test job (HTTP $http_code)"
echo " You may need to manually delete: $test_id"
fi
echo ""
# Test 6: Check companies table (for API key validation)
echo "Test 6: Companies Table Access"
echo "------------------------------"
response=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-H "apikey: $SUPABASE_ANON_KEY" \
-H "Authorization: Bearer $SUPABASE_ANON_KEY" \
"${SUPABASE_URL}/rest/v1/companies?select=id,name&limit=1")
http_code=$(echo "$response" | grep "HTTP_CODE:" | cut -d: -f2)
if [ "$http_code" = "200" ]; then
echo "✅ Can read from companies table"
else
echo "⚠️ Companies table check (HTTP $http_code)"
echo " Note: This is expected if table doesn't exist yet"
fi
echo ""
# Summary
echo "=========================================="
echo "📊 Test Summary"
echo "=========================================="
echo "✅ All critical tests passed!"
echo ""
echo "Next steps:"
echo "1. If companies table test failed, run the SQL migration"
echo "2. Start OpenJobs API: go run cmd/openjobs/main.go"
echo "3. Test API endpoint: curl http://localhost:8080/health"
echo ""