chore: prepare repository for publishing

This commit is contained in:
phamnazage-jpg
2026-05-13 14:42:45 +08:00
parent 55e506b2b5
commit 77e6610fd2
118 changed files with 27373 additions and 1009 deletions

38
scripts/restore.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
if [[ "${1:-}" != "--force" || -z "${2:-}" ]]; then
echo "用法: bash scripts/restore.sh --force <backup.sql|backup.sql.gz>" >&2
exit 1
fi
BACKUP_FILE="$2"
if [[ ! -f "$BACKUP_FILE" ]]; then
echo "备份文件不存在: $BACKUP_FILE" >&2
exit 1
fi
if [[ -f ".env.local" ]]; then
# shellcheck disable=SC1091
source ".env.local"
fi
if [[ -f ".env" ]]; then
# shellcheck disable=SC1091
source ".env"
fi
DB_URL="${DATABASE_URL:-host=/var/run/postgresql dbname=llm_intelligence user=long sslmode=disable}"
echo "开始恢复到目标数据库..."
psql "$DB_URL" -v ON_ERROR_STOP=1 -c "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"
if [[ "$BACKUP_FILE" == *.gz ]]; then
gzip -dc "$BACKUP_FILE" | psql "$DB_URL" -v ON_ERROR_STOP=1
else
psql "$DB_URL" -v ON_ERROR_STOP=1 -f "$BACKUP_FILE"
fi
echo "恢复完成: $BACKUP_FILE"