CoolFace
Apppublic

tramdk/fanpage-manager

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
switch-db.js34 linesDownload Raw Back to scripts
1import fs from 'fs';2import path from 'path';3import { fileURLToPath } from 'url';4 5const __filename = fileURLToPath(import.meta.url);6const __dirname = path.dirname(__filename);7 8const schemaPath = path.join(__dirname, '../prisma/schema.prisma');9const dbType = process.argv[2]; // 'sqlite' or 'postgres'10 11if (!['sqlite', 'postgres'].includes(dbType)) {12  console.error('❌ Vui lòng chọn db type: sqlite hoặc postgres');13  process.exit(1);14}15 16try {17  let content = fs.readFileSync(schemaPath, 'utf8');18  19  if (dbType === 'sqlite') {20    content = content.replace(/provider\s*=\s*"postgresql"/g, 'provider = "sqlite"');21    // Đảm bảo URL cũng phù hợp nếu cần, nhưng Prisma khuyến khích dùng env()22    console.log('✅ Đã chuyển Prisma provider sang: sqlite');23  } else {24    content = content.replace(/provider\s*=\s*"sqlite"/g, 'provider = "postgresql"');25    console.log('✅ Đã chuyển Prisma provider sang: postgresql');26  }27 28  fs.writeFileSync(schemaPath, content);29  console.log('🚀 Tiếp theo: Hãy cập nhật DATABASE_URL trong .env và chạy "npx prisma generate"');30} catch (err) {31  console.error('❌ Lỗi khi chuyển đổi schema:', err.message);32  process.exit(1);33}34