const { Client } = require('pg'); require('dotenv').config(); async function seedInventoryDevices() { console.log('=== Seeding Inventory Devices ==='); const client = new Client({ connectionString: process.env.DATABASE_URL, ssl: false, }); try { await client.connect(); // Sample inventory devices for testing const deviceData = [ { hardwareId: 'EDGE_DEVICE_001', deviceModel: 'EdgeBox Pro v1.0' }, { hardwareId: 'EDGE_DEVICE_002', deviceModel: 'EdgeBox Pro v1.0' }, { hardwareId: 'EDGE_DEVICE_003', deviceModel: 'EdgeBox Pro v1.1' }, { hardwareId: 'SENSOR_NODE_001', deviceModel: 'SensorNode Lite v2.0' }, { hardwareId: 'SENSOR_NODE_002', deviceModel: 'SensorNode Lite v2.0' }, { hardwareId: 'GATEWAY_HUB_001', deviceModel: 'GatewayHub Enterprise v1.0' }, ]; console.log('šŸ“¦ Inserting sample inventory devices...'); for (const device of deviceData) { // Check if device already exists const existsResult = await client.query( 'SELECT id FROM inventory_devices WHERE hardware_id = $1', [device.hardwareId] ); if (existsResult.rows.length === 0) { await client.query( `INSERT INTO inventory_devices (hardware_id, device_model, is_claimed) VALUES ($1, $2, false)`, [device.hardwareId, device.deviceModel] ); console.log(` āœ… Added: ${device.hardwareId} (${device.deviceModel})`); } else { console.log(` ā­ļø Skipped: ${device.hardwareId} (already exists)`); } } // Show current inventory status const inventoryResult = await client.query(` SELECT hardware_id, device_model, is_claimed, created_at FROM inventory_devices ORDER BY created_at DESC `); console.log('\nšŸ“‹ Current Inventory Status:'); inventoryResult.rows.forEach(row => { const status = row.is_claimed ? 'šŸ”“ CLAIMED' : '🟢 AVAILABLE'; console.log(` ${status} ${row.hardware_id} - ${row.device_model || 'No model'}`); }); console.log(`\nāœ… Seeding completed! ${deviceData.length} devices processed.`); } catch (error) { console.error('āŒ Error seeding inventory devices:', error.message); } finally { await client.end(); } } seedInventoryDevices();