File size: 1,165 Bytes
3d777f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const fs = require('fs');
const path = require('path');
const { Pool } = require('pg');
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });

const connectionString = process.env.SUPABASE_DB_URL; // Using the direct Postgres connection string

if (!connectionString) {
  console.error('Error: SUPABASE_DB_URL not found in .env');
  console.log('To run this script, you need the direct PostgreSQL connection string from Supabase (Database -> Settings -> URI).');
  process.exit(1);
}

const pool = new Pool({
  connectionString,
  ssl: {
    rejectUnauthorized: false
  }
});

async function initDB() {
  try {
    console.log('Connecting to PostgreSQL database...');
    const client = await pool.connect();
    
    console.log('Reading schema.sql...');
    const schemaSql = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');
    
    console.log('Executing schema script...');
    await client.query(schemaSql);
    
    console.log('✅ Database schema created successfully!');
    client.release();
  } catch (error) {
    console.error('❌ Error executing schema:', error.message);
  } finally {
    pool.end();
  }
}

initDB();