cangku/backend/scripts/sync_stock_selection_tables.js

35 lines
965 B
JavaScript

'use strict';
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const dataSource = require('../src/config/database');
const cloudDb = require('../src/config/cloudDatabase');
const { syncStockSelectionTables } = require('../src/services/stockSelectionSync');
async function main() {
try {
console.log('[sync-stock-selection] 开始同步条码打标表到系统库');
const result = await syncStockSelectionTables({
syncType: 'script',
onProgress: (payload) => {
if (payload?.stage) {
console.log(`[sync-stock-selection] ${payload.stage}`, payload);
}
},
});
console.log('[sync-stock-selection] 同步完成', result);
} catch (error) {
console.error('[sync-stock-selection] 同步失败:', error);
process.exitCode = 1;
} finally {
await Promise.allSettled([
cloudDb.close(),
dataSource.close(),
]);
}
}
main();