mirror of
https://github.com/HarborGuard/HarborGuard.git
synced 2026-03-23 00:02:41 +08:00
- Removed all SQLite references and functionality - PostgreSQL is now the only supported database - Fixed Trivy cache directory mismatch between Dockerfile and runtime - Updated cache directories to use /workspace/cache consistently - Added Docker resource limits (2 CPU cores, 4GB RAM) to docker-compose.yml - Updated documentation to reflect PostgreSQL-only support - Fixed HOSTNAME binding issue for Windows WSL connectivity - Improved database initialization scripts for PostgreSQL-only operation - Updated .gitignore to exclude PostgreSQL data directory instead of SQLite files - Ensured Prisma client generation at build time Breaking changes: - SQLite databases are no longer supported - DATABASE_URL must now point to a PostgreSQL instance or be omitted for bundled PostgreSQL
62 lines
1.9 KiB
Bash
Executable File
62 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Database Initialization Script
|
|
# Initializes PostgreSQL database with fallback support
|
|
|
|
set -e # Exit on any error
|
|
|
|
echo "[DB] Starting database initialization with fallback support..."
|
|
|
|
# Check if Prisma CLI is available
|
|
if command -v prisma &> /dev/null; then
|
|
echo "[DB] Prisma CLI found"
|
|
else
|
|
echo "[DB] ERROR: Prisma CLI not found. Please ensure Prisma is installed."
|
|
echo "[DB] You can install it with: npm install -g prisma"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if DATABASE_URL is provided
|
|
if [ -z "$DATABASE_URL" ]; then
|
|
echo "[DB] No external DATABASE_URL provided, will use bundled PostgreSQL"
|
|
# The start.sh script will handle bundled PostgreSQL setup
|
|
exit 0
|
|
fi
|
|
|
|
echo "[DB] External DATABASE_URL provided, testing connection..."
|
|
|
|
# Function to test PostgreSQL connection
|
|
test_postgresql_connection() {
|
|
echo "[DB] Testing database connection..."
|
|
if timeout 15s npx prisma db execute --sql "SELECT 1" 2>/dev/null; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Test the external PostgreSQL connection
|
|
if test_postgresql_connection; then
|
|
echo "[DB] Database connection successful"
|
|
echo "[DB] Using external PostgreSQL database"
|
|
echo "[DB] Database URL: ${DATABASE_URL//:*@/:****@}" # Hide password
|
|
|
|
# Run database migrations
|
|
echo "[DB] Running database migrations..."
|
|
if npx prisma migrate deploy; then
|
|
echo "[DB] Migrations applied successfully"
|
|
else
|
|
echo "[DB] Migration failed, trying db push..."
|
|
npx prisma db push --accept-data-loss
|
|
echo "[DB] Database schema synchronized"
|
|
fi
|
|
|
|
echo "[DB] Database initialization completed successfully"
|
|
echo "[DB] Using external PostgreSQL database"
|
|
else
|
|
echo "[DB] ERROR: Failed to connect to external PostgreSQL database"
|
|
echo "[DB] Please check your DATABASE_URL and ensure the database is accessible"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[DB] Initialization completed successfully" |