DB migration. osagoContracts from null to empty array

This commit is contained in:
Selim Mustafaev 2024-03-31 22:02:45 +03:00
parent 9ea088e3f4
commit 70ba09e9b6
2 changed files with 15 additions and 5 deletions

View File

@ -1,8 +1,8 @@
const MongoClient = require('mongodb').MongoClient; import { MongoClient } from 'mongodb';
const dotenv = require('dotenv'); import { config } from 'dotenv';
const dotenvExpand = require('dotenv-expand'); import dotenvExpand from 'dotenv-expand';
let dotenvConf = dotenv.config(); let dotenvConf = config();
dotenvExpand(dotenvConf); dotenvExpand(dotenvConf);
async function addUpdatedDate() { 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 () => { (async () => {
//await addUpdatedDate(); //await addUpdatedDate();
//await addDebugInfoStatus(); //await addDebugInfoStatus();
await fixNullNotes(); //await fixNullNotes();
await fixNullOsagoContracts();
console.log('====== Done ======'); console.log('====== Done ======');
})(); })();

View File

@ -65,6 +65,7 @@ class Vehicle {
v.updatedDate = v.addedDate; v.updatedDate = v.addedDate;
v.events = []; v.events = [];
v.notes = []; v.notes = [];
v.osagoContracts = [];
v.debugInfo = { autocod: new DebugInfo() }; v.debugInfo = { autocod: new DebugInfo() };
return v; return v;
@ -161,6 +162,7 @@ class Vehicle {
v.updatedDate = v.addedDate; v.updatedDate = v.addedDate;
v.events = []; v.events = [];
v.notes = []; v.notes = [];
v.osagoContracts = [];
v.debugInfo = { vin01base: new DebugInfo() }; v.debugInfo = { vin01base: new DebugInfo() };
return v; return v;