forked from techx/quill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Automatic-CheckIn' into frontendcheckin
- Loading branch information
Showing
9 changed files
with
141 additions
and
5 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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,12 @@ | ||
require('dotenv').load({silent: true}); | ||
|
||
// Connect to mongodb | ||
var mongoose = require('mongoose'); | ||
var database = process.env.MONGODB_URI || "mongodb://localhost:27017" | ||
mongoose.connect(database); | ||
|
||
var SettingsController = require('../app/server/controllers/SettingsController'); | ||
|
||
SettingsController.updateRecordsWithMissingFields(function() { | ||
console.log('Updated settings to include missing fields'); | ||
}) |
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,65 @@ | ||
function clone(){ | ||
require('dotenv').load({silent:true}); | ||
// Connect locally to mongodb | ||
|
||
const mongoose = require('mongoose'), | ||
localDB = process.env.MONGODB_URI || "mongodb://localhost:27017", | ||
remoteDB = process.env.REMOTE_URI, | ||
Settings = require('../app/server/models/Settings'), | ||
User = require('../app/server/models/User'); | ||
mongoose.Promise = Promise; | ||
|
||
// Connect to remote db | ||
if(!remoteDB) return console.log("NO REMOTE URI"); | ||
|
||
let local = mongoose.createConnection(localDB); | ||
let remote = mongoose.createConnection(remoteDB); | ||
|
||
console.log("LOCAL DB name => ", local.name); | ||
console.log("REMOTE DB name => ", remote.name); | ||
|
||
|
||
// Gets remote settings | ||
remote.model('Settings').findOne({}).select('-_id') | ||
.then(settingsR => { | ||
console.log("New Settings :", settingsR) | ||
// Updates local settings | ||
return local.model('Settings').findOneAndUpdate({}, settingsR) | ||
}) | ||
.then(settingsPrior => { | ||
console.log('Old Settings :', settingsPrior); | ||
// Droops users | ||
return local.db.dropCollection('users') | ||
}) | ||
.then(() =>{ | ||
console.log("Dropped local user collection"); | ||
// Gets remote users | ||
return remote.model('User').find({}).select('+password +salt +status.admittedBy') | ||
}) | ||
.then(usersR => { | ||
console.log('Amount of remote users :', usersR.length); | ||
let LocalUser = local.model('User'); | ||
let p = usersR.map( user => { | ||
return new Promise((resolve, reject) => { | ||
let u = new LocalUser(user.toObject()); | ||
u.save((err,newUser) => { | ||
if(err) return reject(err) | ||
resolve(newUser); | ||
}) | ||
}); | ||
}) | ||
// Creates users locally | ||
return Promise.all(p) | ||
}) | ||
.then(newUsers => { | ||
console.log('New Users :', newUsers.length); | ||
process.exit(0); | ||
}) | ||
.catch(err =>{ | ||
console.log("ERROR"); | ||
console.log('err :', err); | ||
process.exit(1); | ||
}) | ||
} | ||
|
||
clone(); |