|
|
|
|
|
|
| Write-Host "🚀 Chahua Database Management Console Setup" -ForegroundColor Cyan
|
| Write-Host "=" * 50 -ForegroundColor Gray
|
|
|
|
|
| $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 Test-Command($cmdname) {
|
| return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
|
| }
|
|
|
|
|
| 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
|
| }
|
|
|
|
|
| $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
|
| }
|
|
|
|
|
| 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
|
| }
|
| }
|
|
|
|
|
| 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 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-Process "http://localhost:3000/scripts/database-console"
|
| npm run start
|
| }
|
|
|
|
|
| function Check-DatabaseStatus {
|
| Write-Host "`n🔍 Checking Database Status..." -ForegroundColor Cyan
|
| npm run db:status
|
| }
|
|
|
|
|
| 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 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 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 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 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 }
|
| }
|
| }
|
|
|
|
|
| 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")
|
|
|