diff --git a/migration.js b/migration.js index cb615db..a8eba84 100644 --- a/migration.js +++ b/migration.js @@ -1,8 +1,8 @@ -const MongoClient = require('mongodb').MongoClient; -const dotenv = require('dotenv'); -const dotenvExpand = require('dotenv-expand'); +import { MongoClient } from 'mongodb'; +import { config } from 'dotenv'; +import dotenvExpand from 'dotenv-expand'; -let dotenvConf = dotenv.config(); +let dotenvConf = config(); dotenvExpand(dotenvConf); async function addUpdatedDate() { @@ -64,9 +64,17 @@ async function fixNullNotes() { } } +async function fixNullOsagoContracts() { + let client = await MongoClient.connect(process.env.MONGO_CONNECTION_STRING); + let db = client.db('autocatdev'); + let collection = db.collection('vehicles'); + await collection.updateMany({ osagoContracts: null }, { $set: { osagoContracts: [] } }); +} + (async () => { //await addUpdatedDate(); //await addDebugInfoStatus(); - await fixNullNotes(); + //await fixNullNotes(); + await fixNullOsagoContracts(); console.log('====== Done ======'); })(); diff --git a/models/vehicle.js b/models/vehicle.js index ae45659..b9c5320 100644 --- a/models/vehicle.js +++ b/models/vehicle.js @@ -65,6 +65,7 @@ class Vehicle { v.updatedDate = v.addedDate; v.events = []; v.notes = []; + v.osagoContracts = []; v.debugInfo = { autocod: new DebugInfo() }; return v; @@ -161,6 +162,7 @@ class Vehicle { v.updatedDate = v.addedDate; v.events = []; v.notes = []; + v.osagoContracts = []; v.debugInfo = { vin01base: new DebugInfo() }; return v;