fix(deploy): explain missing RDS database to administrators

This commit is contained in:
姚章浩
2026-09-11 12:25:31 +08:00
parent 6153533b46
commit b4b61c0aa5
2 changed files with 13 additions and 2 deletions
+12 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
}