Files
habitica/migrations/archive/2015/20150906_sync_groups_with_firebase.js
Matteo Pagliazzi 74ba55c20b Upgrade tests tools and lint migrations and scripts (part 2) (#9998)
* upgrade gulp-babel

* upgrade babel-eslint

* upgrade eslint-friendly-formatter

* start upgrading chai

* start to upgrade eslint

* restore skipped tests

* start to upgrqde monk

* fix linting and remove unused file

* fix mocha notifications, and common tests

* fix unit tests

* start to fix initrgration tests

* more integration tests fixes

* upgrade monk to latest version

* lint /scripts

* migrations: start moving to /archive unused migrations and run eslint with --fix

* lint migrations

* fix more integration tests

* fix test
2018-02-17 18:11:24 +01:00

43 lines
1.1 KiB
JavaScript

/*
* Sync groups with Firebase
*/
let mongo = require('mongoskin');
let Firebase = require('Firebase');
let dbserver = 'mongodb://url';
let dbname = 'db';
let db = mongo.db(`${dbserver }/${ dbname }?auto_reconnect`);
let dbGroups = db.collection('groups');
let countGroups = 0;
let firebaseRef = new Firebase('https://' + 'firebase-app' + '.firebaseio.com');
// TODO handle sync errors with firebase?
firebaseRef.authWithCustomToken('firebase-secret', function (err, authData) {
if (err) throw new Error('Impossible to authenticate Firebase');
console.log('Firebase connected, begins work on db');
dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 100}, function (err, group) {
if (err) throw err;
if (group._id !== 'habitrpg') return;
countGroups++;
console.log('Group: ', countGroups);
firebaseRef.child(`rooms/${ group._id}`)
.set({
name: group.name,
});
group.members.forEach(function (member) {
firebaseRef.child(`members/${ group._id }/${ userId}`)
.set(true);
firebaseRef.child(`users/${ member }/rooms/${ group._id}`)
.set(true);
});
});
});