Fixes for reset and calculate scripts

This commit is contained in:
2025-01-16 14:21:33 -05:00
parent 7ec587595a
commit c9aefdc756
4 changed files with 195 additions and 255 deletions

View File

@@ -22,6 +22,9 @@ const METRICS_TABLES = [
'product_metrics',
'product_time_aggregates',
'vendor_metrics',
'vendor_time_metrics',
'category_metrics',
'category_time_metrics',
'category_sales_metrics'
];
@@ -48,19 +51,17 @@ async function resetMetrics() {
connection = await mysql.createConnection(dbConfig);
await connection.beginTransaction();
// Reset existing metrics tables
await connection.query('TRUNCATE TABLE temp_sales_metrics');
await connection.query('TRUNCATE TABLE temp_purchase_metrics');
await connection.query('TRUNCATE TABLE product_metrics');
await connection.query('TRUNCATE TABLE product_time_aggregates');
// Reset vendor metrics tables
await connection.query('TRUNCATE TABLE vendor_metrics');
await connection.query('TRUNCATE TABLE vendor_time_metrics');
// Reset category metrics tables
await connection.query('TRUNCATE TABLE category_metrics');
await connection.query('TRUNCATE TABLE category_time_metrics');
// Reset all metrics tables
for (const table of METRICS_TABLES) {
console.log(`Truncating table: ${table}`);
try {
await connection.query(`TRUNCATE TABLE ${table}`);
console.log(`Successfully truncated: ${table}`);
} catch (err) {
console.error(`Error truncating ${table}:`, err.message);
throw err;
}
}
await connection.commit();
console.log('All metrics tables reset successfully');