-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-pcr-db.js
More file actions
68 lines (57 loc) · 1.99 KB
/
debug-pcr-db.js
File metadata and controls
68 lines (57 loc) · 1.99 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
const { createClient } = require('@supabase/supabase-client');
const fs = require('fs');
const path = require('path');
// Read .env.local manually
const envPath = path.join(__dirname, '.env.local');
const envContent = fs.readFileSync(envPath, 'utf8');
const env = {};
envContent.split('\n').forEach(line => {
const match = line.match(/^\s*([^#\s=]+)\s*=\s*(.*)$/);
if (match) {
let value = match[2].trim();
// Remove quotes if present
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.substring(1, value.length - 1);
}
env[match[1]] = value;
}
});
const supabaseUrl = env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseKey = env.SUPABASE_SERVICE_ROLE_KEY;
if (!supabaseUrl || !supabaseKey) {
console.error('Missing Supabase credentials in .env.local');
process.exit(1);
}
const supabase = createClient(supabaseUrl, supabaseKey);
async function debugData() {
console.log('Querying pcr_data for NIFTY on 2026-01-12...');
// Query last 20 records
const { data, error } = await supabase
.from('pcr_data')
.select('*')
.eq('index_name', 'NIFTY')
.order('captured_at', { ascending: false })
.limit(20);
if (error) {
console.error('Error:', error);
return;
}
console.log(`Found ${data.length} records for NIFTY.`);
data.forEach(r => {
console.log(`ID: ${r.id}, Captured: ${r.captured_at}, PCR: ${r.pcr_value}, Spot: ${r.spot_price}`);
});
// Check if the specific ID exists
const targetId = '4ae4b1a2-ef0d-4858-ba92-409b20c6b96e';
const { data: specific, error: sError } = await supabase
.from('pcr_data')
.select('*')
.eq('id', targetId)
.single();
if (sError) {
console.log(`Record ${targetId} not found by ID.`);
} else {
console.log('\nTarget Record Found:');
console.log(JSON.stringify(specific, null, 2));
}
}
debugData();