# ๐Ÿ›ก๏ธ Chahua Database Management Console - Windows Setup # Enterprise Database Management System for Windows VPS Write-Host "๐Ÿš€ Chahua Database Management Console Setup" -ForegroundColor Cyan Write-Host "=" * 50 -ForegroundColor Gray # Check if running as Administrator $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") if (-not $isAdmin) { Write-Host "โš ๏ธ WARNING: Not running as Administrator" -ForegroundColor Yellow Write-Host "Some operations may require elevated privileges" -ForegroundColor Yellow } # Function to check if a command exists function Test-Command($cmdname) { return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue) } # Check prerequisites Write-Host "`n๐Ÿ” Checking Prerequisites..." -ForegroundColor Yellow if (Test-Command "node") { $nodeVersion = (node --version 2>$null) Write-Host "โœ… Node.js: $nodeVersion" -ForegroundColor Green } else { Write-Host "โŒ Node.js not found. Please install Node.js first." -ForegroundColor Red exit 1 } if (Test-Command "npm") { $npmVersion = (npm --version 2>$null) Write-Host "โœ… NPM: v$npmVersion" -ForegroundColor Green } else { Write-Host "โŒ NPM not found. Please install NPM first." -ForegroundColor Red exit 1 } if (Test-Command "pg_dump") { Write-Host "โœ… PostgreSQL client tools available" -ForegroundColor Green } else { Write-Host "โš ๏ธ PostgreSQL client tools not found in PATH" -ForegroundColor Yellow Write-Host " Database backup features may not work" -ForegroundColor Yellow } # Check if database console exists $consolePath = "scripts\database-console" if (Test-Path $consolePath) { Write-Host "โœ… Database Console files found" -ForegroundColor Green } else { Write-Host "โŒ Database Console files not found at: $consolePath" -ForegroundColor Red Write-Host " Please ensure you're running this from the project root" -ForegroundColor Red exit 1 } # Check .env file if (Test-Path ".env") { Write-Host "โœ… Environment configuration found" -ForegroundColor Green } else { Write-Host "โš ๏ธ .env file not found. Creating from example..." -ForegroundColor Yellow if (Test-Path "config\env.example") { Copy-Item "config\env.example" ".env" Write-Host "โœ… Created .env from example" -ForegroundColor Green Write-Host " Please update .env with your database credentials" -ForegroundColor Cyan } else { Write-Host "โŒ No .env.example found. Please create .env manually" -ForegroundColor Red } } # Display menu function Show-Menu { Write-Host "`n๐ŸŽฏ Chahua Database Management Options:" -ForegroundColor Cyan Write-Host "=" * 40 -ForegroundColor Gray Write-Host "1. ๐ŸŒ Start Database Console (Web Interface)" -ForegroundColor White Write-Host "2. ๐Ÿ” Check Database Status" -ForegroundColor White Write-Host "3. ๐Ÿ”ง Fix Database Issues" -ForegroundColor White Write-Host "4. ๐Ÿ“Š Database Statistics" -ForegroundColor White Write-Host "5. ๐Ÿ—‚๏ธ Module Management" -ForegroundColor White Write-Host "6. ๐Ÿ’พ Backup Database" -ForegroundColor White Write-Host "7. ๐Ÿงช Generate Sample Data" -ForegroundColor White Write-Host "8. ๐Ÿ“‹ List Tables" -ForegroundColor White Write-Host "9. โš™๏ธ Advanced Options" -ForegroundColor White Write-Host "0. ๐Ÿšช Exit" -ForegroundColor Red Write-Host "=" * 40 -ForegroundColor Gray } # Function to start database console function Start-DatabaseConsole { Write-Host "`n๐ŸŒ Starting Chahua Database Console..." -ForegroundColor Cyan Write-Host "Server will be available at: http://localhost:3000" -ForegroundColor Green Write-Host "Console URL: http://localhost:3000/scripts/database-console" -ForegroundColor Green Write-Host "`nPress Ctrl+C to stop the server" -ForegroundColor Yellow # Start server in background and open browser Start-Process "http://localhost:3000/scripts/database-console" npm run start } # Function to check database status function Check-DatabaseStatus { Write-Host "`n๐Ÿ” Checking Database Status..." -ForegroundColor Cyan npm run db:status } # Function to fix database issues function Fix-DatabaseIssues { Write-Host "`n๐Ÿ”ง Database Fix Options:" -ForegroundColor Cyan Write-Host "1. Fix Forum Issues (tags column)" -ForegroundColor White Write-Host "2. Fix Plugin System" -ForegroundColor White Write-Host "3. Fix Payment System" -ForegroundColor White Write-Host "4. Fix Core System" -ForegroundColor White Write-Host "5. Fix Dashboard" -ForegroundColor White Write-Host "6. Fix Bank Transfer" -ForegroundColor White Write-Host "7. Fix All Issues" -ForegroundColor White Write-Host "8. Return to Main Menu" -ForegroundColor Gray $choice = Read-Host "`nSelect option (1-8)" switch ($choice) { "1" { npm run db:fix-forum } "2" { npm run db:fix-plugins } "3" { npm run db:fix-payment } "4" { npm run db:fix-core } "5" { npm run db:fix-dashboard } "6" { npm run db:fix-bank } "7" { Write-Host "๐Ÿ”„ Running all database fixes..." -ForegroundColor Cyan npm run db:fix-core npm run db:fix-payment npm run db:fix-forum npm run db:fix-plugins npm run db:fix-dashboard npm run db:fix-bank } "8" { return } default { Write-Host "โŒ Invalid option" -ForegroundColor Red } } } # Function to show database statistics function Show-DatabaseStats { Write-Host "`n๐Ÿ“Š Database Statistics..." -ForegroundColor Cyan npm run db:list-tables Write-Host "`n๐Ÿ“ˆ Additional Stats:" -ForegroundColor Cyan npm run db:status } # Function for module management function Manage-Modules { Write-Host "`n๐Ÿ—‚๏ธ Database Module Management:" -ForegroundColor Cyan Write-Host "1. Core Module Status" -ForegroundColor White Write-Host "2. Payment Module Status" -ForegroundColor White Write-Host "3. Forum Module Status" -ForegroundColor White Write-Host "4. Plugin Module Status" -ForegroundColor White Write-Host "5. Dashboard Module Status" -ForegroundColor White Write-Host "6. Bank Transfer Module Status" -ForegroundColor White Write-Host "7. All Modules Status" -ForegroundColor White Write-Host "8. Return to Main Menu" -ForegroundColor Gray $choice = Read-Host "`nSelect option (1-8)" switch ($choice) { "1" { npm run db:fix-core } "2" { npm run db:fix-payment } "3" { npm run db:fix-forum } "4" { npm run db:fix-plugins } "5" { npm run db:fix-dashboard } "6" { npm run db:fix-bank } "7" { npm run db:status } "8" { return } default { Write-Host "โŒ Invalid option" -ForegroundColor Red } } } # Function to backup database function Backup-Database { Write-Host "`n๐Ÿ’พ Database Backup..." -ForegroundColor Cyan if (-not (Test-Command "pg_dump")) { Write-Host "โŒ pg_dump not found. Please install PostgreSQL client tools." -ForegroundColor Red return } $timestamp = Get-Date -Format "yyyyMMdd-HHmmss" $backupFile = "backup\chahua-db-$timestamp.sql" Write-Host "Creating backup: $backupFile" -ForegroundColor Green npm run db:backup } # Function for advanced options function Show-AdvancedOptions { Write-Host "`nโš™๏ธ Advanced Options:" -ForegroundColor Cyan Write-Host "1. ๐Ÿ”„ Reset Database (DANGEROUS)" -ForegroundColor Red Write-Host "2. ๐Ÿงน Clear Logs" -ForegroundColor White Write-Host "3. ๐Ÿ” Update Security Settings" -ForegroundColor White Write-Host "4. ๐Ÿ“ View Environment Config" -ForegroundColor White Write-Host "5. ๐Ÿ”ง Install Dependencies" -ForegroundColor White Write-Host "6. ๐Ÿ“Š Performance Test" -ForegroundColor White Write-Host "7. Return to Main Menu" -ForegroundColor Gray $choice = Read-Host "`nSelect option (1-7)" switch ($choice) { "1" { $confirm = Read-Host "โš ๏ธ This will reset ALL data. Type 'RESET' to confirm" if ($confirm -eq "RESET") { npm run db:setup } else { Write-Host "โŒ Reset cancelled" -ForegroundColor Green } } "2" { if (Test-Path "logs") { Remove-Item "logs\*" -Recurse -Force Write-Host "โœ… Logs cleared" -ForegroundColor Green } } "3" { Write-Host "๐Ÿ” Security settings in .env file" -ForegroundColor Cyan if (Test-Path ".env") { Get-Content ".env" | Where-Object { $_ -match "SECURITY|TOKEN|SECRET" } } } "4" { if (Test-Path ".env") { Write-Host "๐Ÿ“ Environment Configuration:" -ForegroundColor Cyan Get-Content ".env" } } "5" { Write-Host "๐Ÿ”ง Installing dependencies..." -ForegroundColor Cyan npm install } "6" { Write-Host "๐Ÿ“Š Running performance test..." -ForegroundColor Cyan npm run test } "7" { return } default { Write-Host "โŒ Invalid option" -ForegroundColor Red } } } # Main menu loop do { Show-Menu $choice = Read-Host "`nSelect option (0-9)" switch ($choice) { "1" { Start-DatabaseConsole } "2" { Check-DatabaseStatus } "3" { Fix-DatabaseIssues } "4" { Show-DatabaseStats } "5" { Manage-Modules } "6" { Backup-Database } "7" { npm run db:sample-data } "8" { npm run db:list-tables } "9" { Show-AdvancedOptions } "0" { Write-Host "`n๐Ÿ‘‹ Goodbye! Thank you for using Chahua Database Console" -ForegroundColor Cyan break } default { Write-Host "โŒ Invalid option. Please select 0-9" -ForegroundColor Red } } if ($choice -ne "0") { Write-Host "`nPress any key to continue..." -ForegroundColor Gray $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") } } while ($choice -ne "0")