From db69b30d062600cc25e7ffdd9344298a308cf8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Sun, 9 Nov 2025 18:36:50 +0100 Subject: [PATCH] feat: add PostgreSQL initialization script for AI stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created database initialization script following the core stack pattern. The script automatically creates required databases on first initialization: - openwebui: Open WebUI application database - litellm: LiteLLM proxy database for API key management and tracking Changes: - Created ai/postgres/init/01-init-databases.sh - Mounted init directory in ai_postgres service - Added automatic privilege grants to AI_DB_USER Note: Init script only runs on first database creation when volume is empty. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- ai/compose.yaml | 1 + ai/postgres/init/01-init-databases.sh | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 ai/postgres/init/01-init-databases.sh diff --git a/ai/compose.yaml b/ai/compose.yaml index 367ea69..e957f8a 100644 --- a/ai/compose.yaml +++ b/ai/compose.yaml @@ -13,6 +13,7 @@ services: POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 volumes: - ai_postgres_data:/var/lib/postgresql/data + - ./postgres/init:/docker-entrypoint-initdb.d healthcheck: test: ["CMD-SHELL", "pg_isready -U ${AI_DB_USER}"] interval: 30s diff --git a/ai/postgres/init/01-init-databases.sh b/ai/postgres/init/01-init-databases.sh new file mode 100755 index 0000000..69e7094 --- /dev/null +++ b/ai/postgres/init/01-init-databases.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -e + +# PostgreSQL initialization script for AI stack +# This script runs on first database initialization +# Creates all databases required by AI services + +echo "Starting AI stack database initialization..." + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + -- Create databases for AI services + -- Open WebUI database + SELECT 'CREATE DATABASE openwebui' + WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'openwebui')\gexec + + -- LiteLLM proxy database + SELECT 'CREATE DATABASE litellm' + WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'litellm')\gexec + + -- Grant privileges to all databases + GRANT ALL PRIVILEGES ON DATABASE openwebui TO $POSTGRES_USER; + GRANT ALL PRIVILEGES ON DATABASE litellm TO $POSTGRES_USER; + + -- Log success + SELECT 'AI stack databases initialized:' AS status; + SELECT datname FROM pg_database + WHERE datname IN ('openwebui', 'litellm') + ORDER BY datname; +EOSQL + +echo "" +echo "✓ PostgreSQL initialization completed" +echo "✓ All AI stack databases created successfully" +echo "" +echo "Databases available:" +echo " • openwebui - Open WebUI application database" +echo " • litellm - LiteLLM proxy database" +echo ""