Migration for adding status to debugInfo
This commit is contained in:
parent
0194f3472b
commit
0d1bce9b67
20
migration.js
20
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 () => {
|
(async () => {
|
||||||
await addUpdatedDate();
|
//await addUpdatedDate();
|
||||||
|
await addDebugInfoStatus();
|
||||||
console.log('====== Done ======');
|
console.log('====== Done ======');
|
||||||
})();
|
})();
|
||||||
Loading…
Reference in New Issue
Block a user