Remove import history tracking from purchase orders import script
This commit is contained in:
@@ -2,7 +2,6 @@ const { outputProgress, formatElapsedTime, estimateRemaining, calculateRate } =
|
||||
|
||||
async function importPurchaseOrders(prodConnection, localConnection) {
|
||||
const startTime = Date.now();
|
||||
let importHistoryId;
|
||||
|
||||
try {
|
||||
// Get last sync info
|
||||
@@ -11,22 +10,6 @@ async function importPurchaseOrders(prodConnection, localConnection) {
|
||||
);
|
||||
const lastSyncTime = syncInfo?.[0]?.last_sync_timestamp || '1970-01-01';
|
||||
|
||||
// Create import history record
|
||||
const [historyResult] = await localConnection.query(`
|
||||
INSERT INTO import_history (
|
||||
table_name,
|
||||
start_time,
|
||||
is_incremental,
|
||||
status
|
||||
) VALUES (
|
||||
'purchase_orders',
|
||||
NOW(),
|
||||
?,
|
||||
'running'
|
||||
)
|
||||
`, [!!syncInfo?.[0]]);
|
||||
importHistoryId = historyResult.insertId;
|
||||
|
||||
outputProgress({
|
||||
operation: "Starting purchase orders import - Initializing",
|
||||
status: "running",
|
||||
@@ -315,49 +298,15 @@ async function importPurchaseOrders(prodConnection, localConnection) {
|
||||
ON DUPLICATE KEY UPDATE last_sync_timestamp = NOW()
|
||||
`);
|
||||
|
||||
// Update import history with final stats
|
||||
const endTime = Date.now();
|
||||
const durationSeconds = Math.round((endTime - startTime) / 1000);
|
||||
|
||||
await localConnection.query(`
|
||||
UPDATE import_history
|
||||
SET
|
||||
end_time = NOW(),
|
||||
duration_seconds = ?,
|
||||
records_added = ?,
|
||||
records_updated = ?,
|
||||
status = 'completed',
|
||||
additional_info = JSON_OBJECT(
|
||||
'total_processed', ?,
|
||||
'last_sync_time', ?,
|
||||
'next_sync_time', NOW()
|
||||
)
|
||||
WHERE id = ?
|
||||
`, [durationSeconds, recordsAdded, recordsUpdated, totalItems, lastSyncTime, importHistoryId]);
|
||||
|
||||
return {
|
||||
status: "complete",
|
||||
totalImported: totalItems,
|
||||
recordsAdded,
|
||||
recordsUpdated,
|
||||
durationSeconds,
|
||||
incrementalUpdate: !!syncInfo?.[0]
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
// Update import history with error
|
||||
if (importHistoryId) {
|
||||
await localConnection.query(`
|
||||
UPDATE import_history
|
||||
SET
|
||||
end_time = NOW(),
|
||||
duration_seconds = ?,
|
||||
status = 'failed',
|
||||
error_message = ?
|
||||
WHERE id = ?
|
||||
`, [Math.round((Date.now() - startTime) / 1000), error.message, importHistoryId]);
|
||||
}
|
||||
|
||||
outputProgress({
|
||||
operation: "Purchase orders import failed",
|
||||
status: "error",
|
||||
|
||||
Reference in New Issue
Block a user