import { Client } from 'pg';

async function createSchema() {
  const client = new Client({
    host: 'localhost',
    port: 5432,
    user: 'postgres',
    password: '',
    database: 'edr_freight',
  });

  try {
    console.log('Connecting to Postgres...');
    await client.connect();
    console.log('Creating schema freight if not exists...');
    await client.query('CREATE SCHEMA IF NOT EXISTS freight');
    console.log('Schema ensured.');
    await client.end();
    process.exit(0);
  } catch (err) {
    console.error('Failed to create schema:', err);
    try { await client.end(); } catch {}
    process.exit(1);
  }
}

createSchema();
