37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
// Script: scripts/clean-migration-fk-idx.js
|
|
// ลบบรรทัดที่มี FK_ หรือ idx_ ในไฟล์ migration ทั้งหมด และแทนที่ด้วย comment
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const MIGRATION_DIR = path.join(__dirname, "../src/migration");
|
|
|
|
function processFile(filePath) {
|
|
const lines = fs.readFileSync(filePath, "utf8").split("\n");
|
|
let changed = false;
|
|
const newLines = lines.map((line) => {
|
|
if (/FK_|idx_/.test(line)) {
|
|
changed = true;
|
|
return " // removed FK_/idx_ auto-cleanup";
|
|
}
|
|
return line;
|
|
});
|
|
if (changed) {
|
|
fs.writeFileSync(filePath, newLines.join("\n"), "utf8");
|
|
console.log("Cleaned:", filePath);
|
|
}
|
|
}
|
|
|
|
function walk(dir) {
|
|
fs.readdirSync(dir).forEach((f) => {
|
|
const fullPath = path.join(dir, f);
|
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
walk(fullPath);
|
|
} else if (f.endsWith(".ts")) {
|
|
processFile(fullPath);
|
|
}
|
|
});
|
|
}
|
|
|
|
walk(MIGRATION_DIR);
|
|
console.log("Migration FK_/idx_ cleanup complete.");
|