-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-migration.mjs
More file actions
74 lines (60 loc) · 2.51 KB
/
deploy-migration.mjs
File metadata and controls
74 lines (60 loc) · 2.51 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
import { createClient } from '@supabase/supabase-js';
import { readFileSync } from 'fs';
const SUPABASE_URL = 'https://mdzzslzwaturlmyhnzzw.supabase.co';
const SERVICE_ROLE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1kenpzbHp3YXR1cmxteWhuenp3Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1OTEwMDg3NCwiZXhwIjoyMDc0Njc2ODc0fQ.2N2l51pfjChvRdMZyl3Lzl0FAPkYLWuynLmfK0zHapE';
const supabase = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, {
auth: { persistSession: false }
});
async function executeMigration() {
try {
console.log('Starting migration deployment...\n');
// Read the migration file
const migrationSQL = readFileSync('./supabase/migrations/0025_performance_optimization_clinical_hours.sql', 'utf8');
// Execute the entire migration
const { data, error } = await supabase.rpc('exec', { sql: migrationSQL });
if (error) {
console.error('Error executing migration:', error);
// Try alternative method - execute via raw query
console.log('\nTrying alternative execution method...');
const response = await fetch(`${SUPABASE_URL}/rest/v1/`, {
method: 'POST',
headers: {
'apikey': SERVICE_ROLE_KEY,
'Authorization': `Bearer ${SERVICE_ROLE_KEY}`,
'Content-Type': 'application/json',
'Prefer': 'return=representation'
},
body: JSON.stringify({ query: migrationSQL })
});
const result = await response.json();
console.log('Alternative method result:', result);
} else {
console.log('Migration executed successfully!');
console.log('Result:', data);
}
// Verify deployment
console.log('\n=== VERIFYING DEPLOYMENT ===\n');
// Check for the RPC functions
console.log('Checking RPC functions...');
const functions = [
'get_weekly_hours_aggregation',
'get_rotation_analytics_aggregated',
'export_hours_filtered'
];
for (const funcName of functions) {
const { data, error } = await supabase.rpc(funcName, {
p_student_id: '00000000-0000-0000-0000-000000000000',
...(funcName === 'get_weekly_hours_aggregation' ? { p_weeks_back: 1 } : {})
}).limit(1);
if (error && !error.message.includes('Student not found') && !error.message.includes('Unauthorized')) {
console.log(` ❌ ${funcName}: NOT FOUND`);
} else {
console.log(` ✓ ${funcName}: EXISTS`);
}
}
} catch (err) {
console.error('Fatal error:', err);
process.exit(1);
}
}
executeMigration();