97 lines
3.1 KiB
PHP
97 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class TestSupabaseConnection extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'app:test-supabase';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Test Supabase PostgreSQL database connection';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('🔗 Testing Supabase Connection...\n');
|
|
|
|
try {
|
|
// Test 1: Basic connection
|
|
$this->info('Test 1: Basic Connection');
|
|
$pdo = DB::connection()->getPdo();
|
|
$this->line(' ✅ Connected to ' . env('DB_HOST'));
|
|
|
|
// Test 2: Query execution
|
|
$this->info('\nTest 2: Query Execution');
|
|
$result = DB::select('SELECT 1');
|
|
$this->line(' ✅ Query executed successfully');
|
|
|
|
// Test 3: Get database info
|
|
$this->info('\nTest 3: Database Information');
|
|
$dbInfo = DB::select("
|
|
SELECT
|
|
datname as database,
|
|
version() as version
|
|
FROM pg_database
|
|
WHERE datname = current_database()
|
|
");
|
|
|
|
if (!empty($dbInfo)) {
|
|
$this->line(' Database: ' . $dbInfo[0]->database);
|
|
$this->line(' Version: ' . $dbInfo[0]->version);
|
|
}
|
|
|
|
// Test 4: Tables
|
|
$this->info('\nTest 4: Existing Tables');
|
|
$tables = DB::select("
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'public'
|
|
ORDER BY table_name
|
|
");
|
|
|
|
if (empty($tables)) {
|
|
$this->line(' ⚠️ No tables found (run migrations)');
|
|
} else {
|
|
$this->line(' ✅ Found ' . count($tables) . ' tables:');
|
|
foreach ($tables as $table) {
|
|
$this->line(' - ' . $table->table_name);
|
|
}
|
|
}
|
|
|
|
// Test 5: User count
|
|
$this->info('\nTest 5: User Data');
|
|
$dosenCount = DB::table('users_dosen')->count();
|
|
$staffCount = DB::table('users_staff')->count();
|
|
$this->line(" Users Dosen: $dosenCount");
|
|
$this->line(" Users Staff: $staffCount");
|
|
|
|
$this->info('\n✅ All tests passed! Supabase connection is working perfectly!');
|
|
return 0;
|
|
|
|
} catch (\Exception $e) {
|
|
$this->error('\n❌ Connection Failed!');
|
|
$this->error('Error: ' . $e->getMessage());
|
|
$this->error('\nPlease check:');
|
|
$this->error('1. DB_HOST in .env');
|
|
$this->error('2. DB_USERNAME and DB_PASSWORD');
|
|
$this->error('3. DB_DATABASE name');
|
|
$this->error('4. IP whitelist in Supabase dashboard');
|
|
return 1;
|
|
}
|
|
}
|
|
}
|