const { Pool } = require('pg');

const pool = new Pool({
  connectionString: 'postgresql://jumpa_admin:JumpaS3cur3%21%40%23@localhost:5432/jumpadb' // Try localhost first
});

async function run() {
  const client = await pool.connect();
  try {
    const res = await client.query(`
      UPDATE system_features 
      SET module = 'JVC' 
      WHERE name IN (
        'Supreme''s Eye (Multiverse)',
        'Chronos Smart Scheduler',
        'The Vault (Recordings)',
        'Omniversal Multi-Stream',
        'Ultra Breakout Matrix',
        'Omniversal Multi-Stream & Ultra Breakout Matrix'
      )
      RETURNING *;
    `);
    console.log("Updated rows via localhost:", res.rowCount);
  } catch (e) {
    console.error("Localhost failed, trying remote...", e.message);
    
    // Try remote if localhost fails
    const remotePool = new Pool({
      connectionString: 'postgresql://jumpa_admin:JumpaS3cur3%21%40%23@xcom-ultra-alpha.ultramodul.xyz:5432/jumpadb'
    });
    const remoteClient = await remotePool.connect();
    try {
      const res2 = await remoteClient.query(`
        UPDATE system_features 
        SET module = 'JVC' 
        WHERE name IN (
          'Supreme''s Eye (Multiverse)',
          'Chronos Smart Scheduler',
          'The Vault (Recordings)',
          'Omniversal Multi-Stream',
          'Ultra Breakout Matrix',
          'Omniversal Multi-Stream & Ultra Breakout Matrix'
        )
        RETURNING *;
      `);
      console.log("Updated rows via remote:", res2.rowCount);
    } catch(err) {
      console.error("Remote failed too:", err.message);
    } finally {
      remoteClient.release();
    }
  } finally {
    client.release();
  }
}

run().catch(console.error).finally(() => process.exit(0));
