Files
telegram-shop/.zscripts/database-runtime-build.sh
2026-08-05 11:10:09 +00:00

34 lines
901 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
#!/bin/bash
set -euo pipefail
PROJECT_DIR="${PROJECT_DIR:-/home/z/my-project}"
BUILD_DIR="${BUILD_DIR:?BUILD_DIR is required}"
SOURCE_DB_DIR="$PROJECT_DIR/db"
SOURCE_DB_PATH="$SOURCE_DB_DIR/custom.db"
TARGET_DB_DIR="$BUILD_DIR/db"
TARGET_DB_PATH="$TARGET_DB_DIR/custom.db"
mkdir -p "$TARGET_DB_DIR"
if [ -f "$SOURCE_DB_PATH" ]; then
echo "🗄️ 复制 Preview 数据库到构建产物..."
cp -a "$SOURCE_DB_DIR/." "$TARGET_DB_DIR/"
else
echo " 未找到 Preview 数据库 db/custom.db将初始化空的生产数据库"
fi
echo "🗄️ 同步构建产物中的数据库结构..."
(
cd "$PROJECT_DIR"
DATABASE_URL="file:$TARGET_DB_PATH" bun run db:push
)
if [ ! -f "$TARGET_DB_PATH" ]; then
echo "❌ 数据库初始化命令执行成功,但未生成 $TARGET_DB_PATH"
exit 1
fi
echo "✅ 构建产物数据库已准备完成"
ls -lah "$TARGET_DB_DIR"