GoldScrape_Api / scripts /create-table.js
Aurum
Initialize clean codebase without binary files
dcc4f27
Raw
History Blame Contribute Delete
1.51 kB
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();