diff --git a/migration.js b/migration.js index 127ec59..fae73c1 100644 --- a/migration.js +++ b/migration.js @@ -21,7 +21,25 @@ async function addUpdatedDate() { } } +async function addDebugInfoStatus() { + let client = await MongoClient.connect(process.env.MONGO_CONNECTION_STRING, { useUnifiedTopology: true }); + let db = client.db('autocatdev'); + let collection = db.collection('vehicles'); + let vehicles = await collection.find().toArray(); + for(let vehicle of vehicles) { + if(vehicle.debugInfo) { + for(const [providerName] of Object.entries(vehicle.debugInfo)) { + if(vehicle.debugInfo[providerName]) { + vehicle.debugInfo[providerName].status = vehicle.debugInfo[providerName].error == null ? 0 : 1; + } + } + await collection.updateOne({ _id: vehicle._id }, { $set: { debugInfo: vehicle.debugInfo } }); + } + } +} + (async () => { - await addUpdatedDate(); + //await addUpdatedDate(); + await addDebugInfoStatus(); console.log('====== Done ======'); })(); \ No newline at end of file