fix(dev): 兼容 Compose 数据库容器启动
保留显式数据库连接配置,自动识别 Compose PostgreSQL 容器及宿主机端口,并在容器不存在时跳过不适用的 Docker 建库。\n\n验证:bash -n;ShellCheck;scripts/create-database.sh;pnpm dev 真实启动 API 与 Web
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
if [[ -n "${AI_GATEWAY_PG_CONTAINER:-}" ]]; then
|
||||
CONTAINER="$AI_GATEWAY_PG_CONTAINER"
|
||||
elif docker inspect easyai-pgvector >/dev/null 2>&1; then
|
||||
@@ -8,7 +10,15 @@ elif docker inspect easyai-pgvector >/dev/null 2>&1; then
|
||||
elif docker inspect postgres >/dev/null 2>&1; then
|
||||
CONTAINER="postgres"
|
||||
else
|
||||
CONTAINER="easyai-pgvector"
|
||||
CONTAINER="$(
|
||||
docker compose -f "${PROJECT_ROOT}/docker-compose.yml" ps -q postgres 2>/dev/null \
|
||||
| head -n 1
|
||||
)"
|
||||
fi
|
||||
|
||||
if [[ -z "$CONTAINER" ]] || ! docker inspect "$CONTAINER" >/dev/null 2>&1; then
|
||||
echo "[ai-gateway] no PostgreSQL Docker container found; set AI_GATEWAY_PG_CONTAINER or create the database through the configured connection" >&2
|
||||
exit 1
|
||||
fi
|
||||
PGUSER="${AI_GATEWAY_PG_USER:-easyai}"
|
||||
DB_NAME="${AI_GATEWAY_DATABASE_NAME:-easyai_ai_gateway}"
|
||||
|
||||
Reference in New Issue
Block a user