const fs = require('fs'); const path = require('path'); const db = require('../db'); async function initDb() { try { const schemaPath = path.join(__dirname, '../schema.sql'); const schemaSql = fs.readFileSync(schemaPath, 'utf8'); console.log('Applying schema...'); await db.query(schemaSql); // Seed Channels const channels = ['general', 'random']; for (const name of channels) { await db.query( `INSERT INTO channels (name) VALUES ($1) ON CONFLICT (name) DO NOTHING`, [name] ); } console.log('Channels seeded.'); console.log('Schema applied successfully.'); process.exit(0); } catch (err) { console.error('Error applying schema:', err); process.exit(1); } } initDb();