This commit is contained in:
hailin 2025-05-18 18:05:14 +08:00
parent f70c11c4de
commit 6417d87481
1 changed files with 25 additions and 6 deletions

View File

@ -1,20 +1,39 @@
#!/bin/bash #!/bin/bash
set -e set -e
# 标记文件路径(使用系统级目录)
FLAG_DIR="/var/lib/db-init"
FLAG_FILE="$FLAG_DIR/.db_initialized"
# 数据库连接配置
export PGUSER=supabase_admin export PGUSER=supabase_admin
export PGPASSWORD=postgres export PGPASSWORD=postgres
export PGHOST=127.0.0.1 export PGHOST=127.0.0.1
export PGPORT=5432 export PGPORT=5432
export PGDATABASE=postgres export PGDATABASE=postgres
echo "Running migrations..." # 提前创建标记目录
mkdir -p "$FLAG_DIR"
for file in $(ls /supabase/migrations/*.sql | sort); do # 如果标记已存在,跳过执行
echo "Executing $file" if [ -f "$FLAG_FILE" ]; then
echo "✅ Database has already been initialized, skipping."
exit 0
fi
echo "🚀 Starting database initialization..."
# 执行 migrations
echo "📂 Running migrations..."
for file in $(ls /supabase/chatai-ui/supabase/migrations/*.sql | sort); do
echo " ▶ Executing $file"
psql -f "$file" psql -f "$file"
done done
echo "Running seed.sql..." # 执行 seed.sql
psql -f /supabase/seed.sql echo "🌱 Running seed.sql..."
psql -f /supabase/chatai-ui/supabase/seed.sql
echo "All SQL scripts executed successfully." # 写入初始化标记
touch "$FLAG_FILE"
echo "✅ Database initialization complete. Marked as initialized at $FLAG_FILE"