accounts/scripts/import_schema_clean.sh

40 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
#
# scripts/import_schema_clean.sh
# ---------------------------------------------
# Import a cleaned schema.sql file into PostgreSQL.
# Safe for re-run (幂等导入)
# ---------------------------------------------
set -euo pipefail
# ====== Configuration ======
DB_URL=${1:-"postgres://shenlan:password@127.0.0.1:5432/account?sslmode=disable"}
IN_FILE=${2:-"/tmp/schema_clean.sql"}
# ====== Validation ======
if [ ! -f "$IN_FILE" ]; then
echo "❌ File not found: $IN_FILE"
echo "💡 请先运行 export_schema_clean.sh 导出 schema"
exit 1
fi
if ! command -v psql >/dev/null 2>&1; then
echo "❌ 未检测到 psql请先安装 PostgreSQL 客户端"
exit 1
fi
# ====== Import schema ======
echo ">>> Importing schema into database"
echo "---------------------------------------------"
echo "Database: $DB_URL"
echo "Schema: $IN_FILE"
echo "---------------------------------------------"
psql "$DB_URL" -v ON_ERROR_STOP=1 -f "$IN_FILE"
echo ""
echo "✅ Schema import completed successfully"
echo "---------------------------------------------"