From b4b61c0aa59fd99df5541dcb8ba2d122287ee6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Fri, 11 Sep 2026 12:25:31 +0800 Subject: [PATCH] fix(deploy): explain missing RDS database to administrators --- deploy/dobotai-dingtalk/rds-schema-init.sh | 13 ++++++++++++- scripts/containerized_deployment_test.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/deploy/dobotai-dingtalk/rds-schema-init.sh b/deploy/dobotai-dingtalk/rds-schema-init.sh index 7886a4c..d705fff 100644 --- a/deploy/dobotai-dingtalk/rds-schema-init.sh +++ b/deploy/dobotai-dingtalk/rds-schema-init.sh @@ -17,7 +17,18 @@ if not (url.startswith('postgres://') or url.startswith('postgresql://')): raise Path(sys.argv[2]).write_text('DATABASE_URL='+url+'\n',encoding='utf-8'); os.chmod(sys.argv[2],0o600) PY rds_shell() { docker run --rm -i --network host --env-file "$temp_env" postgres:16-alpine sh -ec "$1"; } -rds_shell 'pg_isready -d "$DATABASE_URL" >/dev/null' +rds_shell 'pg_isready -d "$DATABASE_URL" >/dev/null' || true +if ! probe_error="$(rds_shell 'exec psql -At -v ON_ERROR_STOP=1 "$DATABASE_URL" -c "SELECT 1"' 2>&1)"; then + case "$probe_error" in + *"does not exist"*|*"不存在"*) + echo "阿里云RDS目标数据库不存在;请RDS管理员创建DobotAI专用数据库并授予应用账号连接和建表权限。" >&2 + ;; + *) + echo "无法连接阿里云RDS目标数据库;请管理员检查网络、白名单、TLS、账号权限和连接串。" >&2 + ;; + esac + exit 1 +fi sql() { rds_shell 'exec psql -v ON_ERROR_STOP=1 "$DATABASE_URL"'; } sql_at() { rds_shell 'exec psql -At -v ON_ERROR_STOP=1 "$DATABASE_URL"'; } state=$(printf "%s\n" "WITH expected(name) AS (VALUES ('turns'),('session_mappings'),('messages'),('coverage_decisions'),('support_cases'),('system_config_revisions'),('administrators'),('setting_sessions'),('user_preferences'),('reasoning_mode_states'),('reasoning_mode_turns')) SELECT CASE WHEN to_regclass('public.turns') IS NULL AND (SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public')=0 THEN 'empty' WHEN (SELECT COUNT(*) FROM expected e JOIN information_schema.tables t ON t.table_schema='public' AND t.table_name=e.name)=11 THEN 'normal' ELSE 'inconsistent' END;" | sql_at) diff --git a/scripts/containerized_deployment_test.go b/scripts/containerized_deployment_test.go index 03d60cf..46806a4 100644 --- a/scripts/containerized_deployment_test.go +++ b/scripts/containerized_deployment_test.go @@ -46,7 +46,7 @@ func TestRDSInitializerOnlyInitializesEmptySchemaAndRejectsInconsistentSchema(t t.Fatal(err) } source := string(data) - for _, required := range []string{"pg_isready", "to_regclass('public.turns')", "empty", "normal", "inconsistent", "*.up.sql", "DATABASE_URL", "postgres:16-alpine"} { + for _, required := range []string{"pg_isready", "to_regclass('public.turns')", "empty", "normal", "inconsistent", "数据库不存在", "*.up.sql", "DATABASE_URL", "postgres:16-alpine"} { if !strings.Contains(source, required) { t.Errorf("RDS initializer missing %q", required) }