#!/bin/bash
cd /var/www/sneakerpicks
PASS="HzWrn2rMMxUYWO6OT5X0PScIVEvSjQMup9YSLIrkPQ"

# Try direct to pooler port 5432
node -e "
const pg = require('pg');
const pool = new pg.Pool({ connectionString: 'postgresql://postgres:${PASS}@localhost:5432/sneakerpicks' });
pool.query('SELECT COUNT(*) FROM products').then(r => console.log('Port 5432 Products:', r.rows[0].count)).catch(e => console.error('Port 5432 Error:', e.message)).finally(() => pool.end());
"

# Try port 6543
node -e "
const pg = require('pg');
const pool = new pg.Pool({ connectionString: 'postgresql://postgres:${PASS}@localhost:6543/sneakerpicks' });
pool.query('SELECT COUNT(*) FROM products').then(r => console.log('Port 6543 Products:', r.rows[0].count)).catch(e => console.error('Port 6543 Error:', e.message)).finally(() => pool.end());
"

# Try connecting directly to the container IP
DB_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' supabase-db)
echo "DB container IP: $DB_IP"
node -e "
const pg = require('pg');
const pool = new pg.Pool({ connectionString: 'postgresql://postgres:${PASS}@${DB_IP}:5432/sneakerpicks' });
pool.query('SELECT COUNT(*) FROM products').then(r => console.log('Direct IP Products:', r.rows[0].count)).catch(e => console.error('Direct IP Error:', e.message)).finally(() => pool.end());
"
