pfitzpaddy / ngm-reportEngine

SailsJS Rest API service for reporting
1 stars 14 forks source link

update(stocks): migrate sails associations to async processing #169

Closed drfaustusfade closed 4 years ago

drfaustusfade commented 4 years ago

+additional db updates, see comment for details

// remove report, locations for monthes after March
db.getCollection("stockreport").remove({report_year: 2020, report_month: {$gte: 3}});
db.getCollection("stocklocation").remove({report_year: 2020, report_month: {$gte: 3}});

// clean up unlinked hanging records
db.getCollection("stockwarehouse").remove({"organization_id" : null})
db.getCollection("stocklocation").remove({"report_id" : null});
db.getCollection("stock").remove({"location_id" : null});

// update stockwarehouse organization_id reference from ObjectId to String
db.getCollection("stockwarehouse").find({"organization_id" : {$ne: null}}).forEach(function(d){
        print(d.organization_id.valueOf());
        d.organization_id = d.organization_id.valueOf();
        db.getCollection("stockwarehouse").save(d);
});

// update stocklocation report_id reference from ObjectId to String
db.getCollection("stocklocation").find({"report_id" : {$ne: null}}).forEach(function(d){
        print(d.report_id.valueOf());
        d.report_id = d.report_id.valueOf();
        db.getCollection("stocklocation").save(d);
});

// update stock location_id reference from ObjectId to String
db.getCollection("stock").find({"report_id" : {$ne: null}}).forEach(function(d){
        print(d.location_id.valueOf());
        d.location_id = d.location_id.valueOf();
        db.getCollection("stock").save(d);
});
pfitzpaddy commented 4 years ago

Updated on DEV and PROD