chahua-database-manager / archive /database-console-setup.bat
chahuadev's picture
Upload 40 files
8eeb77a verified
@echo off
title Chahua Database Management Console - Windows VPS
color 0B
echo.
echo ========================================
echo 🛡️ Chahua Database Console Setup
echo Enterprise Database Management System
echo ========================================
echo.
REM Check if Node.js is installed
where node >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
echo ❌ Node.js not found. Please install Node.js first.
echo Download from: https://nodejs.org/
pause
exit /b 1
)
REM Check if NPM is installed
where npm >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
echo ❌ NPM not found. Please install NPM first.
pause
exit /b 1
)
REM Get Node.js version
for /f "tokens=*" %%i in ('node --version 2^>nul') do set NODE_VERSION=%%i
echo ✅ Node.js: %NODE_VERSION%
REM Get NPM version
for /f "tokens=*" %%i in ('npm --version 2^>nul') do set NPM_VERSION=%%i
echo ✅ NPM: v%NPM_VERSION%
REM Check PostgreSQL client tools
where pg_dump >nul 2>nul
if %ERRORLEVEL% EQU 0 (
echo ✅ PostgreSQL client tools available
) else (
echo ⚠️ PostgreSQL client tools not found in PATH
echo Database backup features may not work
)
REM Check if database console exists
if exist "scripts\database-console" (
echo ✅ Database Console files found
) else (
echo ❌ Database Console files not found
echo Please ensure you're running this from the project root
pause
exit /b 1
)
REM Check .env file
if exist ".env" (
echo ✅ Environment configuration found
) else (
echo ⚠️ .env file not found
if exist "config\env.example" (
echo Creating .env from example...
copy "config\env.example" ".env" >nul
echo ✅ Created .env from example
echo Please update .env with your database credentials
) else (
echo ❌ No .env.example found. Please create .env manually
)
)
echo.
:MENU
cls
echo.
echo ========================================
echo 🎯 Chahua Database Management Options
echo ========================================
echo.
echo 1. 🌐 Start Database Console (Web Interface)
echo 2. 🔍 Check Database Status
echo 3. 🔧 Fix Database Issues
echo 4. 📊 Database Statistics
echo 5. 🗂️ Module Management
echo 6. 💾 Backup Database
echo 7. 🧪 Generate Sample Data
echo 8. 📋 List Tables
echo 9. ⚙️ Advanced Options
echo 0. 🚪 Exit
echo.
echo ========================================
echo.
set /p choice="Select option (0-9): "
if "%choice%"=="1" goto START_CONSOLE
if "%choice%"=="2" goto CHECK_STATUS
if "%choice%"=="3" goto FIX_ISSUES
if "%choice%"=="4" goto SHOW_STATS
if "%choice%"=="5" goto MANAGE_MODULES
if "%choice%"=="6" goto BACKUP_DB
if "%choice%"=="7" goto SAMPLE_DATA
if "%choice%"=="8" goto LIST_TABLES
if "%choice%"=="9" goto ADVANCED_OPTIONS
if "%choice%"=="0" goto EXIT
echo ❌ Invalid option. Please select 0-9
pause
goto MENU
:START_CONSOLE
cls
echo.
echo 🌐 Starting Chahua Database Console...
echo Server will be available at: http://localhost:3000
echo Console URL: http://localhost:3000/scripts/database-console
echo.
echo Press Ctrl+C to stop the server
echo.
start http://localhost:3000/scripts/database-console
call npm run start
goto MENU
:CHECK_STATUS
cls
echo.
echo 🔍 Checking Database Status...
echo.
call npm run db:status
echo.
pause
goto MENU
:FIX_ISSUES
cls
echo.
echo ========================================
echo 🔧 Database Fix Options
echo ========================================
echo.
echo 1. Fix Forum Issues (tags column)
echo 2. Fix Plugin System
echo 3. Fix Payment System
echo 4. Fix Core System
echo 5. Fix Dashboard
echo 6. Fix Bank Transfer
echo 7. Fix All Issues
echo 8. Return to Main Menu
echo.
set /p fix_choice="Select option (1-8): "
if "%fix_choice%"=="1" call npm run db:fix-forum
if "%fix_choice%"=="2" call npm run db:fix-plugins
if "%fix_choice%"=="3" call npm run db:fix-payment
if "%fix_choice%"=="4" call npm run db:fix-core
if "%fix_choice%"=="5" call npm run db:fix-dashboard
if "%fix_choice%"=="6" call npm run db:fix-bank
if "%fix_choice%"=="7" (
echo 🔄 Running all database fixes...
call npm run db:fix-core
call npm run db:fix-payment
call npm run db:fix-forum
call npm run db:fix-plugins
call npm run db:fix-dashboard
call npm run db:fix-bank
)
if "%fix_choice%"=="8" goto MENU
if not "%fix_choice%"=="8" (
echo.
pause
)
goto MENU
:SHOW_STATS
cls
echo.
echo 📊 Database Statistics...
echo.
call npm run db:list-tables
echo.
echo 📈 Additional Stats:
call npm run db:status
echo.
pause
goto MENU
:MANAGE_MODULES
cls
echo.
echo ========================================
echo 🗂️ Database Module Management
echo ========================================
echo.
echo 1. Core Module Status
echo 2. Payment Module Status
echo 3. Forum Module Status
echo 4. Plugin Module Status
echo 5. Dashboard Module Status
echo 6. Bank Transfer Module Status
echo 7. All Modules Status
echo 8. Return to Main Menu
echo.
set /p mod_choice="Select option (1-8): "
if "%mod_choice%"=="1" call npm run db:fix-core
if "%mod_choice%"=="2" call npm run db:fix-payment
if "%mod_choice%"=="3" call npm run db:fix-forum
if "%mod_choice%"=="4" call npm run db:fix-plugins
if "%mod_choice%"=="5" call npm run db:fix-dashboard
if "%mod_choice%"=="6" call npm run db:fix-bank
if "%mod_choice%"=="7" call npm run db:status
if "%mod_choice%"=="8" goto MENU
if not "%mod_choice%"=="8" (
echo.
pause
)
goto MENU
:BACKUP_DB
cls
echo.
echo 💾 Database Backup...
echo.
where pg_dump >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
echo ❌ pg_dump not found. Please install PostgreSQL client tools.
echo.
pause
goto MENU
)
call npm run db:backup
echo.
pause
goto MENU
:SAMPLE_DATA
cls
echo.
echo 🧪 Generating Sample Data...
echo.
call npm run db:sample-data
echo.
pause
goto MENU
:LIST_TABLES
cls
echo.
echo 📋 Listing Database Tables...
echo.
call npm run db:list-tables
echo.
pause
goto MENU
:ADVANCED_OPTIONS
cls
echo.
echo ========================================
echo ⚙️ Advanced Options
echo ========================================
echo.
echo 1. 🔄 Reset Database (DANGEROUS)
echo 2. 🧹 Clear Logs
echo 3. 🔐 Update Security Settings
echo 4. 📝 View Environment Config
echo 5. 🔧 Install Dependencies
echo 6. 📊 Performance Test
echo 7. Return to Main Menu
echo.
set /p adv_choice="Select option (1-7): "
if "%adv_choice%"=="1" (
echo.
echo ⚠️ This will reset ALL data.
set /p confirm="Type 'RESET' to confirm: "
if /i "!confirm!"=="RESET" (
call npm run db:setup
) else (
echo ❌ Reset cancelled
)
echo.
pause
)
if "%adv_choice%"=="2" (
if exist "logs" (
del /q "logs\*.*" 2>nul
echo ✅ Logs cleared
) else (
echo ⚠️ Logs directory not found
)
echo.
pause
)
if "%adv_choice%"=="3" (
echo 🔐 Security settings in .env file
if exist ".env" (
findstr /i "SECURITY TOKEN SECRET" ".env"
) else (
echo ❌ .env file not found
)
echo.
pause
)
if "%adv_choice%"=="4" (
if exist ".env" (
echo 📝 Environment Configuration:
type ".env"
) else (
echo ❌ .env file not found
)
echo.
pause
)
if "%adv_choice%"=="5" (
echo 🔧 Installing dependencies...
call npm install
echo.
pause
)
if "%adv_choice%"=="6" (
echo 📊 Running performance test...
call npm run test
echo.
pause
)
if "%adv_choice%"=="7" goto MENU
if not "%adv_choice%"=="7" goto MENU
:EXIT
cls
echo.
echo ========================================
echo 👋 Thank you for using
echo Chahua Database Console
echo ========================================
echo.
echo Built with ❤️ by Chahua Development Thailand
echo.
pause
exit /b 0