flnxi-Wu/scripts/tools/verify-prisma.sh
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

146 lines
3.9 KiB
Bash

#!/bin/bash
# Prisma 验证脚本
echo "=========================================="
echo " Prisma 状态检查"
echo "=========================================="
echo ""
cd /www/wwwroot/sucai 2>/dev/null || cd .
echo "[1] 检查 Schema 文件..."
if [ -f "prisma/schema.prisma" ]; then
echo "✅ prisma/schema.prisma 存在"
echo ""
echo "数据库提供商:"
grep "provider" prisma/schema.prisma | head -1 | sed 's/^/ /'
else
echo "❌ prisma/schema.prisma 不存在"
fi
echo ""
echo "[2] 检查 Prisma 包..."
if [ -d "node_modules/prisma" ]; then
PRISMA_VERSION=$(npm list prisma --depth=0 2>/dev/null | grep prisma@ | awk '{print $2}')
echo "✅ prisma: $PRISMA_VERSION"
else
echo "❌ prisma 包未安装"
fi
if [ -d "node_modules/@prisma/client" ]; then
CLIENT_VERSION=$(npm list @prisma/client --depth=0 2>/dev/null | grep @prisma/client@ | awk '{print $2}')
echo "✅ @prisma/client: $CLIENT_VERSION"
else
echo "❌ @prisma/client 包未安装"
fi
echo ""
echo "[3] 检查生成的客户端..."
if [ -d "node_modules/.prisma/client" ]; then
echo "✅ node_modules/.prisma/client/ 存在"
# 检查关键文件
FILES=("index.js" "index.d.ts" "schema.prisma")
for file in "${FILES[@]}"; do
if [ -f "node_modules/.prisma/client/$file" ]; then
SIZE=$(ls -lh "node_modules/.prisma/client/$file" | awk '{print $5}')
echo " ✅ $file ($SIZE)"
else
echo " ❌ $file 不存在"
fi
done
# 显示目录大小
echo ""
echo "客户端大小:"
du -sh node_modules/.prisma/client/ | awk '{print " " $1}'
else
echo "❌ node_modules/.prisma/client/ 不存在"
echo ""
echo "需要运行: npx prisma generate"
fi
echo ""
echo "[4] 检查生成的模型..."
if [ -f "node_modules/.prisma/client/index.d.ts" ]; then
echo "可用的模型:"
grep "export type" node_modules/.prisma/client/index.d.ts | \
grep -E "(User|Material|Category|Scene)" | \
sed 's/export type / - /' | \
sed 's/ = .*//'
else
echo "❌ 类型定义文件不存在"
fi
echo ""
echo "[5] 检查环境变量..."
if [ -f ".env" ]; then
echo "✅ .env 文件存在"
if grep -q "DATABASE_URL" .env; then
# 隐藏密码
DB_URL=$(grep "DATABASE_URL" .env | sed 's/:[^:@]*@/:***@/')
echo " $DB_URL"
else
echo " ⚠️ DATABASE_URL 未配置"
fi
else
echo "⚠️ .env 文件不存在"
fi
echo ""
echo "[6] 测试 Prisma CLI..."
if command -v npx &> /dev/null; then
echo "Prisma CLI 版本:"
npx prisma --version | head -3 | sed 's/^/ /'
else
echo "❌ npx 未安装"
fi
echo ""
echo "[7] 尝试导入测试..."
cat > /tmp/test-prisma-import.js << 'EOF'
try {
const { PrismaClient } = require('.prisma/client/default');
console.log('✅ Prisma 客户端导入成功');
console.log('✅ PrismaClient:', typeof PrismaClient);
process.exit(0);
} catch (error) {
console.log('❌ Prisma 客户端导入失败');
console.log('错误:', error.message);
process.exit(1);
}
EOF
node /tmp/test-prisma-import.js 2>&1
rm -f /tmp/test-prisma-import.js
echo ""
echo "=========================================="
echo " 检查完成"
echo "=========================================="
echo ""
# 给出建议
if [ ! -d "node_modules/.prisma/client" ]; then
echo "🎯 需要执行:"
echo " npx prisma generate"
echo ""
elif [ ! -f "node_modules/.prisma/client/index.js" ]; then
echo "🎯 客户端未完整生成,需要重新生成:"
echo " rm -rf node_modules/.prisma"
echo " npx prisma generate"
echo ""
else
echo "✅ Prisma 客户端状态正常"
echo ""
echo "🎯 可用命令:"
echo " npx prisma studio # 打开数据库管理界面"
echo " npx prisma db push # 同步数据库结构"
echo " npm run build # 构建项目"
echo ""
fi