feat: Add standalone script for enhanced Bygma CSV import with validation test: Create simple database test to show current state and product counts test: Develop enhanced validation demo to simulate problematic CSV data handling test: Implement price validation tests with higher limits for edge cases test: Conduct real enhanced validation test with actual Bygma CSV file test: Test validation improvements with known problematic data test: Validate logic of cleaning and validating CSV rows without database test: Test improved VareNr cleaning functionality to remove spaces
71 lines
2.4 KiB
JavaScript
71 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Standalone script to run enhanced Bygma CSV import
|
|
* This properly initializes the database connection before import
|
|
*/
|
|
|
|
require('dotenv').config();
|
|
const BygmaPrisbogImportService = require('./backend/src/services/bygmaPrisbogImportService');
|
|
const databaseService = require('./backend/src/services/databaseService');
|
|
const path = require('path');
|
|
|
|
async function runEnhancedImport() {
|
|
const csvFile = './frontend/firmadata/subvendor/bygma/PrisBog_20250918090450_38178059_ Tømrer- og Snedker Mikael Holck ApS_ 156.csv';
|
|
|
|
try {
|
|
console.log('🔧 Initializing database connection...');
|
|
await databaseService.initialize();
|
|
console.log('✅ Database connection established');
|
|
|
|
console.log('🚀 Starting Bygma CSV import with enhanced validation...');
|
|
console.log('📁 File:', csvFile);
|
|
console.log('⏰ Started at:', new Date().toISOString());
|
|
|
|
const importService = new BygmaPrisbogImportService();
|
|
const result = await importService.importPrisbog(csvFile, 'enhanced-validation-production');
|
|
|
|
console.log('\n✅ Import completed successfully!');
|
|
console.log('📊 Final Results:');
|
|
console.log(JSON.stringify(result, null, 2));
|
|
|
|
// Show import statistics
|
|
if (result.stats) {
|
|
console.log('\n📈 Import Statistics:');
|
|
console.log(` Total rows processed: ${result.stats.totalRows}`);
|
|
console.log(` Successful imports: ${result.stats.successfulRows}`);
|
|
console.log(` Failed imports: ${result.stats.failedRows}`);
|
|
console.log(` New products: ${result.stats.newProducts}`);
|
|
console.log(` Updated products: ${result.stats.updatedProducts}`);
|
|
console.log(` Updated prices: ${result.stats.updatedPrices}`);
|
|
|
|
if (result.stats.failedRows > 0) {
|
|
console.log(`\n⚠️ Failed rows: ${result.stats.failedRows}`);
|
|
console.log('This represents enhanced validation catching data quality issues.');
|
|
}
|
|
}
|
|
|
|
console.log('\n⏰ Completed at:', new Date().toISOString());
|
|
process.exit(0);
|
|
|
|
} catch (error) {
|
|
console.error('❌ Import failed:', error.message);
|
|
console.error('Stack:', error.stack);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Handle graceful shutdown
|
|
process.on('SIGINT', () => {
|
|
console.log('\n🛑 Import interrupted by user');
|
|
process.exit(1);
|
|
});
|
|
|
|
process.on('SIGTERM', () => {
|
|
console.log('\n🛑 Import terminated');
|
|
process.exit(1);
|
|
});
|
|
|
|
// Run the import
|
|
runEnhancedImport();
|