-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute-migration.js
More file actions
44 lines (35 loc) · 1.27 KB
/
execute-migration.js
File metadata and controls
44 lines (35 loc) · 1.27 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
const https = require('https');
const fs = require('fs');
const SUPABASE_URL = 'https://mdzzslzwaturlmyhnzzw.supabase.co';
const SERVICE_ROLE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1kenpzbHp3YXR1cmxteWhuenp3Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1OTEwMDg3NCwiZXhwIjoyMDc0Njc2ODc0fQ.2N2l51pfjChvRdMZyl3Lzl0FAPkYLWuynLmfK0zHapE';
// Read the migration SQL file
const sql = fs.readFileSync('/Users/tanner-osterkamp/MentoLoop/supabase/migrations/0025_performance_optimization_clinical_hours.sql', 'utf8');
// Execute SQL via Supabase REST API
const data = JSON.stringify({ query: sql });
const options = {
hostname: 'mdzzslzwaturlmyhnzzw.supabase.co',
port: 443,
path: '/rest/v1/rpc/exec_sql',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': SERVICE_ROLE_KEY,
'Authorization': `Bearer ${SERVICE_ROLE_KEY}`,
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log('Status Code:', res.statusCode);
console.log('Response:', responseData);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();