File size: 1,514 Bytes
dcc4f27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

require('dotenv').config();
const { createClient } = require('@supabase/supabase-js');

const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY;

if (!supabaseUrl || !supabaseKey) {
  console.error('Missing SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY in .env');
  process.exit(1);
}

const supabase = createClient(supabaseUrl, supabaseKey);

async function main() {
  try {
    console.log('Creating price_records table...');
    const { error } = await supabase.rpc('exec_sql', {
      sql: `
        CREATE TABLE IF NOT EXISTS price_records (
          date DATE PRIMARY KEY,
          gold24k NUMERIC NOT NULL,
          silver999 NUMERIC,
          source TEXT DEFAULT 'IBJA'
        );
        CREATE INDEX IF NOT EXISTS idx_price_records_date ON price_records(date);
      `
    });
    
    if (error) {
      console.error('Error creating table via RPC (not set up). Please create table manually in Supabase SQL Editor with this SQL:');
      console.log(`
        CREATE TABLE IF NOT EXISTS price_records (
          date DATE PRIMARY KEY,
          gold24k NUMERIC NOT NULL,
          silver999 NUMERIC,
          source TEXT DEFAULT 'IBJA'
        );
        CREATE INDEX IF NOT EXISTS idx_price_records_date ON price_records(date);
      `);
    } else {
      console.log('✅ Table created successfully!');
    }
  } catch (err) {
    console.error('Error:', err);
    console.log('Please create table manually in Supabase SQL Editor!');
  }
}

main();