const { Pool } = require('pg');
const fs = require('fs');
const path = require('path');
require('dotenv').config();

const pool = new Pool({
	host: process.env.DB_HOST || 'localhost',
	port: process.env.DB_PORT || 5432,
	database: process.env.DB_NAME || 'bekind',
	user: process.env.DB_USER || 'postgres',
	password: process.env.DB_PASSWORD,
});

async function runMigration() {
	const client = await pool.connect();
	try {
		console.log('🚀 Running migration 003-add-platform-support.sql...');

		const filePath = path.join(__dirname, '../migrations/003-add-platform-support.sql');
		const sql = fs.readFileSync(filePath, 'utf8');

		await client.query(sql);
		console.log('✅ Migration 003 completed successfully!');
	} catch (error) {
		console.error('❌ Migration failed:', error);
		throw error;
	} finally {
		client.release();
		await pool.end();
	}
}

runMigration().catch((err) => {
	console.error(err);
	process.exit(1);
});
