import { readFileSync, writeFileSync } from 'fs'; const filePath = './src/db/drizzle/0000_groovy_red_skull.sql'; const content = readFileSync(filePath, 'utf-8'); const lines = content.split('\n'); let removedCount = 0; const cleaned: string[] = []; for (const line of lines) { // 匹配 CONSTRAINT "表名_字段名_key数字" UNIQUE(...) 形式的约束(有数字后缀的是重复) const match = line.match(/^\s*CONSTRAINT\s+"\w+_key\d+"\s+UNIQUE/i); if (match) { console.log(`[REMOVE] ${line.trim()}`); removedCount++; continue; } cleaned.push(line); } writeFileSync(filePath, cleaned.join('\n')); console.log(`\n[DONE] Removed ${removedCount} duplicate constraints`);