feat: add script to clean duplicate constraints in SQL file

- Introduced a new script `clean-duplicate-constraints.ts` that reads the SQL file
  and removes duplicate UNIQUE constraints identified by a numeric suffix in their names.
- The script logs the removed constraints and outputs the cleaned content back to the file.
This commit is contained in:
2026-03-30 02:39:38 +08:00
parent d9442b9875
commit 5b0a68ad67
2 changed files with 22 additions and 6595 deletions

View File

@@ -0,0 +1,22 @@
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`);