[FIX] Resolve ER_DUP_ENTRY during cctv module migration

This commit is contained in:
choibk 2026-01-26 09:39:44 +09:00
parent 0efe144b09
commit 2f210d3b34

View File

@ -446,7 +446,15 @@ const initTables = async () => {
await db.query(insert, ['cctv', 'CCTV', false, null]); await db.query(insert, ['cctv', 'CCTV', false, null]);
} else { } else {
// One-time update: Rename 'monitoring' code to 'cctv' (migration) // One-time update: Rename 'monitoring' code to 'cctv' (migration)
await db.query("UPDATE system_modules SET code = 'cctv' WHERE code = 'monitoring'"); // Use subquery or check if cctv exists to avoid ER_DUP_ENTRY
const [cctvExists] = await db.query("SELECT 1 FROM system_modules WHERE code = 'cctv'");
if (cctvExists.length > 0) {
// If cctv already exists, just remove monitoring if it's there
await db.query("DELETE FROM system_modules WHERE code = 'monitoring'");
} else {
// If cctv doesn't exist, try renaming monitoring
await db.query("UPDATE system_modules SET code = 'cctv' WHERE code = 'monitoring'");
}
} }
console.log('✅ Tables Initialized'); console.log('✅ Tables Initialized');