const { Pool } = require('pg'); const fs = require('fs'); const path = require('path'); require('dotenv').config(); // Disable SSL verification for Supabase pooler process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; async function runMigration() { const connectionString = process.env.DATABASE_URL?.replace('?sslmode=require', ''); const pool = new Pool({ connectionString, ssl: true }); try { console.log('Connecting to database...'); await pool.query('SELECT 1'); console.log('Connected!\n'); // Read the migration file const migrationPath = path.join(__dirname, '../supabase/migrations/20260206000000_users_and_servers.sql'); const sql = fs.readFileSync(migrationPath, 'utf8'); console.log('Running users_and_servers migration...\n'); // Execute the entire SQL file as a single transaction await pool.query(sql); console.log('✅ Migration complete!'); // Verify tables exist const tables = await pool.query(` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name IN ('users', 'servers', 'channels', 'messages', 'server_members') `); console.log('\nVerified tables created:'); tables.rows.forEach(row => console.log(' ✓', row.table_name)); } catch (error) { console.error('Migration error:', error.message); // If tables already exist error, try checking what exists if (error.message.includes('already exists')) { console.log('\nSome tables already exist. Checking current state...'); const tables = await pool.query(` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name `); console.log('Existing tables:', tables.rows.map(r => r.table_name).join(', ')); } } finally { await pool.end(); } } runMigration();