- Reorganize docs into 'Core deployment guides' and 'Setup and configuration' subdirectories - Consolidate redundant documentation files (ACR, pipelines, deployment guides) - Add documentation consolidation plan - Update backend database factory and logger services - Update migration script and docker-compose configurations - Add PostgreSQL setup script
89 lines
2.7 KiB
Bash
Executable File
89 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Script om PostgreSQL database volledig te resetten
|
||
# Dit simuleert een green field deployment
|
||
# Gebruikt docker-compose.dev.yml voor development setup
|
||
|
||
set -e
|
||
|
||
COMPOSE_FILE="docker-compose.dev.yml"
|
||
|
||
echo "🔄 PostgreSQL Database Reset Script"
|
||
echo "===================================="
|
||
echo ""
|
||
|
||
# Check if docker-compose file exists
|
||
if [ ! -f "$COMPOSE_FILE" ]; then
|
||
echo "⚠️ $COMPOSE_FILE not found, trying docker-compose.yml..."
|
||
COMPOSE_FILE="docker-compose.yml"
|
||
fi
|
||
|
||
# Check if docker-compose is running
|
||
if docker-compose -f "$COMPOSE_FILE" ps 2>/dev/null | grep -q "postgres.*Up"; then
|
||
echo "📦 PostgreSQL container is running"
|
||
echo ""
|
||
|
||
# Stop containers
|
||
echo "⏹️ Stopping containers..."
|
||
docker-compose -f "$COMPOSE_FILE" down
|
||
echo "✅ Containers stopped"
|
||
echo ""
|
||
else
|
||
echo "ℹ️ Containers are not running"
|
||
echo ""
|
||
fi
|
||
|
||
# Remove PostgreSQL volume (this deletes all data!)
|
||
echo "🗑️ Removing PostgreSQL volume (this deletes ALL data)..."
|
||
read -p "Are you sure you want to delete all PostgreSQL data? (yes/no): " confirm
|
||
|
||
if [ "$confirm" != "yes" ]; then
|
||
echo "❌ Aborted. No data was deleted."
|
||
exit 1
|
||
fi
|
||
|
||
# Try to find volume name
|
||
VOLUME_NAME=$(docker volume ls | grep postgres_data | awk '{print $2}' | head -1)
|
||
if [ -n "$VOLUME_NAME" ]; then
|
||
docker volume rm "$VOLUME_NAME" 2>/dev/null || echo "⚠️ Volume not found (might already be deleted)"
|
||
echo "✅ Volume removed"
|
||
else
|
||
echo "⚠️ No postgres_data volume found"
|
||
fi
|
||
echo ""
|
||
|
||
# Start containers again
|
||
echo "🚀 Starting containers with fresh database..."
|
||
docker-compose -f "$COMPOSE_FILE" up -d postgres
|
||
|
||
# Wait for PostgreSQL to be ready
|
||
echo "⏳ Waiting for PostgreSQL to be ready..."
|
||
timeout=30
|
||
counter=0
|
||
until docker-compose -f "$COMPOSE_FILE" exec -T postgres pg_isready -U cmdb > /dev/null 2>&1; do
|
||
sleep 1
|
||
counter=$((counter + 1))
|
||
if [ $counter -ge $timeout ]; then
|
||
echo "❌ Timeout waiting for PostgreSQL"
|
||
exit 1
|
||
fi
|
||
done
|
||
echo "✅ PostgreSQL is ready"
|
||
echo ""
|
||
|
||
# Create database (if needed)
|
||
echo "📊 Creating database..."
|
||
echo " Note: Single database is used by default (contains all tables)"
|
||
docker-compose -f "$COMPOSE_FILE" exec -T postgres psql -U cmdb -c "CREATE DATABASE cmdb_insight;" 2>/dev/null || echo "ℹ️ Database cmdb_insight already exists or will be created automatically"
|
||
echo "✅ Database ready"
|
||
echo ""
|
||
|
||
echo "✨ PostgreSQL database has been reset!"
|
||
echo ""
|
||
echo "Next steps:"
|
||
echo "1. Start the backend locally: cd backend && npm run dev"
|
||
echo "2. The normalized schema will be created automatically on first start"
|
||
echo "3. Run schema discovery: npm run generate-schema (in backend/)"
|
||
echo "4. Start syncing data from Jira"
|
||
echo ""
|