Files
BattleBot/src/scripts/testSupabaseConnection.js
VinceC a8e836fd5b Add help system, deployment docs, and improve setup
Introduces a new interactive help command with button navigation, adds a detailed DEPLOYMENT.md guide, and improves server setup validation and error handling. Updates command registration to include all 9 games, adds version reporting, enhances Docker deployment with a multi-platform script, and removes local .env files from the repo. Also refactors bot startup for better diagnostics and graceful shutdown.
2025-07-13 04:00:39 -05:00

134 lines
5.3 KiB
JavaScript

require('dotenv').config();
const { createClient } = require('@supabase/supabase-js');
async function testSupabaseConnection() {
console.log('🔧 Testing Supabase Connection...\n');
// Check environment variables
console.log('📋 Environment Variables:');
console.log(`SUPABASE_URL: ${process.env.SUPABASE_URL ? '✅ Set' : '❌ Missing'}`);
console.log(`SUPABASE_KEY: ${process.env.SUPABASE_KEY ? '✅ Set' : '❌ Missing'}`);
if (!process.env.SUPABASE_URL || !process.env.SUPABASE_KEY) {
console.log('\n❌ Missing required environment variables');
console.log('Make sure you have SUPABASE_URL and SUPABASE_KEY set in your .env file');
return;
}
console.log(`\nURL: ${process.env.SUPABASE_URL}`);
console.log(`Key: ${process.env.SUPABASE_KEY.substring(0, 20)}...\n`);
try {
// Initialize Supabase client (same as in main bot)
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_KEY
);
console.log('📡 Testing basic connection...');
// Test 1: Check basic connection
const { data, error } = await supabase.from('games').select('count', { count: 'exact', head: true });
if (error) {
console.log('❌ Basic connection failed:', error.message);
return;
}
console.log('✅ Basic connection successful');
// Test 2: Fetch all games
console.log('\n🎮 Testing games table...');
const { data: games, error: gamesError } = await supabase
.from('games')
.select('id, name, active')
.order('name');
if (gamesError) {
console.log('❌ Games query failed:', gamesError.message);
return;
}
console.log(`✅ Found ${games.length} total games:`);
games.forEach(game => {
console.log(` ${game.active ? '✅' : '❌'} ${game.name} (ID: ${game.id})`);
});
// Test 3: Fetch active games only
console.log('\n🔥 Testing active games filter...');
const { data: activeGames, error: activeError } = await supabase
.from('games')
.select('id, name')
.eq('active', true)
.order('name');
if (activeError) {
console.log('❌ Active games query failed:', activeError.message);
return;
}
console.log(`✅ Found ${activeGames.length} active games:`);
activeGames.forEach(game => {
console.log(` 🎯 ${game.name} (ID: ${game.id})`);
});
// Test 4: Test servers table
console.log('\n🏠 Testing servers table...');
const { data: servers, error: serversError } = await supabase
.from('servers')
.select('id, discord_server_id, server_name, active')
.limit(5);
if (serversError) {
console.log('❌ Servers query failed:', serversError.message);
} else {
console.log(`✅ Found ${servers.length} servers (showing first 5):`);
servers.forEach(server => {
console.log(` ${server.active ? '✅' : '❌'} ${server.server_name} (Discord ID: ${server.discord_server_id})`);
});
}
// Test 5: Test active_subscriptions view
console.log('\n📋 Testing active_subscriptions view...');
const { data: subscriptions, error: subsError } = await supabase
.from('active_subscriptions')
.select('*')
.limit(5);
if (subsError) {
console.log('❌ Active subscriptions query failed:', subsError.message);
} else {
console.log(`✅ Found ${subscriptions.length} active subscriptions (showing first 5):`);
subscriptions.forEach(sub => {
console.log(` 🎮 ${sub.game_name} → Server ${sub.discord_server_id} → Channel ${sub.notification_channel_id}`);
});
}
// Test 6: Test specific game lookup (simulate autocomplete)
console.log('\n🔍 Testing specific game lookup (autocomplete simulation)...');
const testGameName = 'VAIL'; // Try to find a common game
const { data: specificGame, error: specificError } = await supabase
.from('games')
.select('id, name')
.eq('name', testGameName)
.eq('active', true)
.single();
if (specificError) {
console.log(`❌ Specific game lookup failed for "${testGameName}":`, specificError.message);
} else {
console.log(`✅ Found specific game: ${specificGame.name} (ID: ${specificGame.id})`);
}
console.log('\n🎉 All tests completed successfully!');
console.log('\n💡 If autocomplete still isn\'t working, check:');
console.log(' 1. Environment variables are set correctly in Coolify');
console.log(' 2. Bot has been restarted after fixing the code');
console.log(' 3. Discord slash commands have been re-deployed');
console.log(' 4. Try the /subscribe command to see if games appear there');
} catch (error) {
console.log('❌ Unexpected error:', error.message);
console.log('Stack:', error.stack);
}
}
testSupabaseConnection().catch(console.error);