feat: add PostgreSQL initialization script for AI stack
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
38
ai/postgres/init/01-init-databases.sh
Executable file
38
ai/postgres/init/01-init-databases.sh
Executable file
@@ -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 ""
|
||||
Reference in New Issue
Block a user