diff --git a/docker-compose.yml b/docker-compose.yml index 7d3452a..d3f8877 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -753,7 +753,7 @@ services: environment: <<: *proxy-env BACKEND_INTERNAL_URL: http://postiz:3000 - DATABASE_URL: "postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/postgres?schema=postiz" + DATABASE_URL: "postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/postiz" DISABLE_REGISTRATION: ${POSTIZ_DISABLE_REGISTRATION} FRONTEND_URL: ${POSTIZ_HOSTNAME:+https://}${POSTIZ_HOSTNAME} IS_GENERAL: "true" # Required for self-hosting. @@ -902,7 +902,7 @@ services: WAHA_DASHBOARD_PASSWORD: ${WAHA_DASHBOARD_PASSWORD} WAHA_DASHBOARD_USERNAME: ${WAHA_DASHBOARD_USERNAME} WAHA_ENGINE: ${WAHA_ENGINE} - WHATSAPP_SESSIONS_POSTGRESQL_URL: postgres://postgres:${POSTGRES_PASSWORD}@postgres:5432/postgres?sslmode=disable + WHATSAPP_SESSIONS_POSTGRESQL_URL: postgres://postgres:${POSTGRES_PASSWORD}@postgres:5432/waha?sslmode=disable WHATSAPP_SWAGGER_ENABLED: ${WHATSAPP_SWAGGER_ENABLED:-true} WHATSAPP_SWAGGER_PASSWORD: ${WHATSAPP_SWAGGER_PASSWORD} WHATSAPP_SWAGGER_USERNAME: ${WHATSAPP_SWAGGER_USERNAME} @@ -1105,7 +1105,7 @@ services: POSTGRES_PORT: 5432 POSTGRES_USER: postgres POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_DATABASE: postgres + POSTGRES_DATABASE: lightrag POSTGRES_MAX_CONNECTIONS: 12 POSTGRES_VECTOR_INDEX_TYPE: HNSW POSTGRES_HNSW_M: 16 diff --git a/scripts/apply_update.sh b/scripts/apply_update.sh index d241a54..b87f268 100755 --- a/scripts/apply_update.sh +++ b/scripts/apply_update.sh @@ -96,6 +96,9 @@ $COMPOSE_CMD -p "localai" "${COMPOSE_FILES_FOR_PULL[@]}" pull --ignore-buildable log_info "Running Services..." bash "$RUN_SERVICES_SCRIPT" || { log_error "Failed to start services. Check logs for details."; exit 1; } +# Initialize PostgreSQL databases for services (creates if not exist) +bash "$SCRIPT_DIR/init_databases.sh" || { log_warning "Database initialization had issues, but continuing..."; } + log_success "Update application completed successfully!" # --- Fix file permissions --- diff --git a/scripts/init_databases.sh b/scripts/init_databases.sh new file mode 100755 index 0000000..883e714 --- /dev/null +++ b/scripts/init_databases.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# ============================================================================= +# init_databases.sh - Create isolated PostgreSQL databases for services +# ============================================================================= +# This script runs during install/update and creates databases if they don't exist. +# Safe to run multiple times - only creates missing databases. +# +# Usage: Called automatically from install.sh and update.sh +# ============================================================================= + +source "$(dirname "$0")/utils.sh" && init_paths + +# List of databases to create (add new services here) +# Note: n8n uses the default 'postgres' database +DATABASES=( + "langfuse" + "lightrag" + "nocodb" + "postiz" + "waha" +) + +log_header "Initializing PostgreSQL Databases" + +# Ensure postgres is running and healthy +log_info "Waiting for PostgreSQL to be ready..." +MAX_WAIT=60 +WAITED=0 + +while ! docker exec postgres pg_isready -U postgres > /dev/null 2>&1; do + if [ $WAITED -ge $MAX_WAIT ]; then + log_error "PostgreSQL did not become ready in ${MAX_WAIT}s" + exit 1 + fi + sleep 1 + ((WAITED++)) +done + +log_success "PostgreSQL is ready" + +# Create databases +CREATED=0 +EXISTING=0 + +for db in "${DATABASES[@]}"; do + # Check if database exists + EXISTS=$(docker exec postgres psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname = '$db'" 2>/dev/null) + + if [ "$EXISTS" = "1" ]; then + log_info "Database '$db' already exists" + ((EXISTING++)) + else + log_info "Creating database '$db'..." + if docker exec postgres psql -U postgres -c "CREATE DATABASE $db" > /dev/null 2>&1; then + log_success "Database '$db' created" + ((CREATED++)) + else + log_error "Failed to create database '$db'" + fi + fi +done + +log_divider +log_success "Database initialization complete: $CREATED created, $EXISTING already existed" diff --git a/scripts/install.sh b/scripts/install.sh index 8e78a7c..e4c205f 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -123,6 +123,9 @@ show_step 6 8 "Running Services" bash "$SCRIPT_DIR/06_run_services.sh" || { log_error "Running Services failed"; exit 1; } log_success "Running Services complete!" +# Initialize PostgreSQL databases for services (creates if not exist) +bash "$SCRIPT_DIR/init_databases.sh" || { log_warning "Database initialization had issues, but continuing..."; } + show_step 7 8 "Generating Final Report" # --- Installation Summary --- log_info "Installation Summary:"