403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/project-slim/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/project-slim/setup_database.sh
#!/bin/bash

# RepoRev Database Migration Script
# This script sets up the PostgreSQL database using your schema

echo "🗄️  RepoRev Database Setup"
echo "========================="

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

print_status() {
    echo -e "${GREEN}[INFO]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# Check if schema.sql exists
if [ ! -f "database/schema.sql" ]; then
    print_error "Schema file not found at database/schema.sql"
    exit 1
fi

print_status "Found schema file at database/schema.sql"

# Get database connection details
read -p "Database host (localhost): " DB_HOST
DB_HOST=${DB_HOST:-localhost}

read -p "Database name (reporev): " DB_NAME
DB_NAME=${DB_NAME:-reporev}

read -p "Database username (postgres): " DB_USER
DB_USER=${DB_USER:-postgres}

read -s -p "Database password: " DB_PASS
echo

read -p "Database port (5432): " DB_PORT
DB_PORT=${DB_PORT:-5432}

# Set PGPASSWORD for non-interactive connection
export PGPASSWORD="$DB_PASS"

# Test connection
print_status "Testing database connection..."
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -c "SELECT version();" > /dev/null 2>&1

if [ $? -ne 0 ]; then
    print_error "Failed to connect to PostgreSQL server"
    print_error "Please check your connection details and try again"
    exit 1
fi

print_status "✅ Successfully connected to PostgreSQL server"

# Create database if it doesn't exist
print_status "Creating database '$DB_NAME' if it doesn't exist..."
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -c "CREATE DATABASE $DB_NAME;" 2>/dev/null

# Check if database exists now
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "SELECT 1;" > /dev/null 2>&1

if [ $? -eq 0 ]; then
    print_status "✅ Database '$DB_NAME' is ready"
else
    print_error "❌ Failed to create or access database '$DB_NAME'"
    exit 1
fi

# Import schema
print_status "Importing schema from database/schema.sql..."
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f database/schema.sql

if [ $? -eq 0 ]; then
    print_status "✅ Schema imported successfully"
else
    print_error "❌ Failed to import schema"
    print_warning "You may need to check the schema file for PostgreSQL compatibility"
    exit 1
fi

# Update .env file if it exists
if [ -f ".env" ]; then
    print_status "Updating .env file with database configuration..."
    
    # Backup .env
    cp .env .env.backup
    
    # Update database settings
    sed -i.bak "s/DB_HOST=.*/DB_HOST=$DB_HOST/" .env
    sed -i.bak "s/DB_NAME=.*/DB_NAME=$DB_NAME/" .env
    sed -i.bak "s/DB_USER=.*/DB_USER=$DB_USER/" .env
    sed -i.bak "s/DB_PASS=.*/DB_PASS=$DB_PASS/" .env
    sed -i.bak "s/DB_PORT=.*/DB_PORT=$DB_PORT/" .env
    
    print_status "✅ Updated .env file with database settings"
fi

# Test the setup
print_status "Testing database tables..."
TABLE_COUNT=$(psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -t -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'repo_%';")

if [ "$TABLE_COUNT" -gt 0 ]; then
    print_status "✅ Found $TABLE_COUNT RepoRev tables in the database"
    
    # Show created tables
    echo ""
    echo "Created tables:"
    psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'repo_%' ORDER BY table_name;"
else
    print_warning "⚠️  No RepoRev tables found. The schema import may have failed."
fi

# Clear password from environment
unset PGPASSWORD

echo ""
print_status "🎉 Database setup completed!"
echo ""
print_status "Your database is now ready for the RepoRev application."
print_status "You can now test the application with:"
echo "  php test_schema.php"
echo ""
print_status "Connection details:"
echo "  Host: $DB_HOST"
echo "  Port: $DB_PORT"
echo "  Database: $DB_NAME"
echo "  Username: $DB_USER"

Youez - 2016 - github.com/yon3zu
LinuXploit