-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changing who and latestChangeBy field from ldapUid to user mongo ID, …
…migration script included relates #429
- Loading branch information
1 parent
a26890b
commit cdd826c
Showing
2 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const models = require('../../server/lib/model') | ||
const {EditLog} = require('../../server/lib/edit-logs') | ||
const async = require('async') | ||
const _ = require('lodash') | ||
|
||
console.log('starting migration') | ||
models.connect() | ||
|
||
async.waterfall([ | ||
next => { | ||
// get mongoid ldapuid index | ||
models.People.aggregate([{$match:{ldapUid:{$ne:null}}},{$project:{_id:1, ldapUid:1}}]).then(data => { | ||
console.log(data.length) | ||
return next(null, data) | ||
}) | ||
}, | ||
(data,next) => { | ||
// update edtilogs | ||
async.parallelLimit( | ||
data.map(e => (nextParallel) => EditLog.updateMany( | ||
{who:e.ldapUid}, | ||
{who:e._id}, | ||
(error,cursor) => nextParallel(null, cursor.modifiedCount))), | ||
100, | ||
(err, counts) => { | ||
console.log(`wrote ${_.sum(counts)} modifications on editLogs`) | ||
return next(null, data) | ||
}) | ||
}, | ||
(data,next) => { | ||
// update edtilogs | ||
async.parallelLimit( | ||
data.map(e => (nextParallel) => models.People.updateMany( | ||
{latestChangeBy:e.ldapUid}, | ||
{latestChangeBy:e._id}, | ||
(error,cursor) => nextParallel(null, cursor.modifiedCount))), | ||
100, | ||
(err, counts) => { | ||
console.log(`wrote ${_.sum(counts)} modifications on People`) | ||
return next(null, data) | ||
}) | ||
}, | ||
(data,next) => { | ||
// update edtilogs | ||
async.parallelLimit( | ||
data.map(e => (nextParallel) => models.Organization.updateMany( | ||
{latestChangeBy:e.ldapUid}, | ||
{latestChangeBy:e._id}, | ||
(error,cursor) => nextParallel(null, cursor.modifiedCount))), | ||
100, | ||
(err, counts) => { | ||
console.log(`wrote ${_.sum(counts)} modifications on People`) | ||
return next(null, data) | ||
}) | ||
}, | ||
(data,next) => { | ||
// update edtilogs | ||
async.parallelLimit( | ||
data.map(e => (nextParallel) => models.Activity.updateMany( | ||
{latestChangeBy:e.ldapUid}, | ||
{latestChangeBy:e._id}, | ||
(error,cursor) => nextParallel(null, cursor.modifiedCount))), | ||
100, | ||
(err, counts) => { | ||
console.log(`wrote ${_.sum(counts)} modifications on Activity`) | ||
return next(null) | ||
}) | ||
} | ||
],error => { | ||
if (error){ | ||
console.log(error) | ||
process.exit(1); | ||
} | ||
process.exit(0); | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters