rename flattenUser to loopbackMigration
add stories migration to script
This commit is contained in:
@ -16,6 +16,14 @@ var providers = [
|
|||||||
'linkedin'
|
'linkedin'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// create async console.logs
|
||||||
|
function debug() {
|
||||||
|
var args = [].slice.call(arguments);
|
||||||
|
process.nextTick(function() {
|
||||||
|
console.log.apply(console, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function createConnection(URI) {
|
function createConnection(URI) {
|
||||||
return Rx.Observable.create(function(observer) {
|
return Rx.Observable.create(function(observer) {
|
||||||
MongoClient.connect(URI, function(err, database) {
|
MongoClient.connect(URI, function(err, database) {
|
||||||
@ -33,6 +41,7 @@ function createQuery(db, collection, options, batchSize) {
|
|||||||
cursor.batchSize(batchSize || 20);
|
cursor.batchSize(batchSize || 20);
|
||||||
// Cursor.each will yield all doc from a batch in the same tick,
|
// Cursor.each will yield all doc from a batch in the same tick,
|
||||||
// or schedule getting next batch on nextTick
|
// or schedule getting next batch on nextTick
|
||||||
|
debug('opening cursor for %s', collection);
|
||||||
cursor.each(function (err, doc) {
|
cursor.each(function (err, doc) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return observer.onError(err);
|
return observer.onError(err);
|
||||||
@ -44,6 +53,7 @@ function createQuery(db, collection, options, batchSize) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return Rx.Disposable.create(function () {
|
return Rx.Disposable.create(function () {
|
||||||
|
debug('closing cursor for %s', collection);
|
||||||
cursor.close();
|
cursor.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -132,18 +142,42 @@ var userIdentityCount = users
|
|||||||
// count how many times insert completes
|
// count how many times insert completes
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
Rx.Observable.merge(
|
var storyCount = dbObservable
|
||||||
|
.flatMap(function(db) {
|
||||||
|
return createQuery(db, 'stories', {});
|
||||||
|
})
|
||||||
|
.bufferWithCount(20)
|
||||||
|
.withLatestFrom(dbObservable, function(stories, db) {
|
||||||
|
return {
|
||||||
|
stories: stories,
|
||||||
|
db: db
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.flatMap(function(dats) {
|
||||||
|
return insertMany(dats.db, 'stories', dats.stories, { w: 1 });
|
||||||
|
})
|
||||||
|
.count();
|
||||||
|
|
||||||
|
Rx.Observable.combineLatest(
|
||||||
userIdentityCount,
|
userIdentityCount,
|
||||||
userSavesCount
|
userSavesCount,
|
||||||
|
storyCount,
|
||||||
|
function(userIdentCount, userCount, storyCount) {
|
||||||
|
return {
|
||||||
|
userIdentCount: userIdentCount * 20,
|
||||||
|
userCount: userCount * 20,
|
||||||
|
storyCount: storyCount * 20
|
||||||
|
};
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
function(_count) {
|
function(countObj) {
|
||||||
count += _count * 20;
|
count = countObj;
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
console.error('an error occured', err, err.stack);
|
console.error('an error occured', err, err.stack);
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
console.log('finished with %s documents processed', count);
|
console.log('finished with ', count);
|
||||||
}
|
}
|
||||||
);
|
);
|
Reference in New Issue
Block a user