const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

async function resetDatabase() {
  console.log('Resetting database...');
  
  try {
    // Drop and recreate the database
    const { stdout, stderr } = await execAsync(`
      PGPASSWORD=placebo_password psql -h localhost -U placebo_user -d postgres -c "DROP DATABASE IF EXISTS placebo_backend_db;"
      PGPASSWORD=placebo_password psql -h localhost -U placebo_user -d postgres -c "CREATE DATABASE placebo_backend_db;"
    `);
    
    if (stderr && !stderr.includes('warning')) {
      console.error('Error:', stderr);
      return;
    }
    
    console.log('Database reset successfully!');
  } catch (error) {
    console.error('Failed to reset database:', error.message);
  }
}

resetDatabase();