ERP-node/temp_copy_data.js

64 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2026-03-01 03:39:00 +09:00
const { Pool } = require("pg");
const devPool = new Pool({ connectionString: "postgresql://postgres:ph0909!!@39.117.244.52:11132/plm", ssl: false });
const prodPool = new Pool({ connectionString: "postgresql://postgres:vexplor0909!!@211.115.91.141:11134/plm", ssl: false });
const tablesToCopy = [
"cascading_auto_fill_group", "cascading_auto_fill_mapping", "cascading_condition",
"cascading_hierarchy_group", "cascading_hierarchy_level", "cascading_mutual_exclusion",
"category_values", "equipment_info", "excel_mapping_template",
"menu_screen_group_items", "menu_screen_groups", "production_plan_mng",
"production_plan_order_rel", "report_menu_mapping", "schedule_history",
"schedule_mng", "schedule_source_mapping", "screen_layouts_pop",
"screen_layouts_v1", "screen_layouts_v2", "screen_layouts_v3",
"category_column_mapping", "numbering_rule_parts", "numbering_rules"
];
async function copyData() {
console.log("=== 데이터 복사 시작 ===\n");
for (const table of tablesToCopy) {
try {
// 개발 DB에서 데이터 조회
const dataRes = await devPool.query(`SELECT * FROM ${table}`);
if (dataRes.rows.length === 0) {
console.log(`⏭️ ${table}: 0건 (스킵)`);
continue;
}
// 컬럼 목록
const columns = Object.keys(dataRes.rows[0]);
const colList = columns.map(c => `"${c}"`).join(", ");
const placeholders = columns.map((_, i) => `$${i + 1}`).join(", ");
// 배치 INSERT
let inserted = 0;
for (const row of dataRes.rows) {
const values = columns.map(col => row[col]);
try {
await prodPool.query(
`INSERT INTO ${table} (${colList}) VALUES (${placeholders}) ON CONFLICT DO NOTHING`,
values
);
inserted++;
} catch(e) {
// 개별 에러는 스킵
// console.log(` 에러: ${e.message.substring(0, 50)}`);
}
}
console.log(`${table}: ${inserted}/${dataRes.rows.length}건 복사`);
} catch(e) {
console.log(`${table}: ${e.message.substring(0, 80)}`);
}
}
console.log("\n=== 완료 ===");
devPool.end();
prodPool.end();
}
copyData().catch(e => { console.error(e); devPool.end(); prodPool.end(); });