- 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.
23 lines
702 B
TypeScript
23 lines
702 B
TypeScript
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`);
|