This repository has been archived by the owner on Dec 31, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For a number of reasons, we've decided that MongoDB is unsuitable for this project. The nature of our data is relational, and getting everything to work together will require some hacks and be brittle in nature. Reasons for the switch to Postgres include: * To store emails and associate them with users we have two options. Either we embed emails in user documents and use GridFs when they exceed 16mb, or we place them all in a single collection and search them via an index. The first option results in the inability to run queries for particular emails and has a number of other performance issue. The second method will result in potentially billions of emails in a single document, with queries suffering in performance against such a large number. * MongoDB is not ACID compliant. Atomicitiy and isolation are particularly important as they ensure predictability when uploading large datasets and allay concurrency concerns with multi-user accounts. * In light of the above, Postgres is ACID compliant & relational. It also offers additional features useful for handling multi-user accounts & permissions that will be useful in protecting sensitive data (emails).
- Loading branch information
1 parent
e0dff50
commit 6708179
Showing
16 changed files
with
234 additions
and
105 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,6 @@ | ||
module.exports = { | ||
config: './server/config/sequelize_config.js', | ||
migrationsPath: './server/migrations', | ||
modelsPath: './server/models', | ||
seedersPath: './server/seed' | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,28 @@ | ||
const Google = require('./passport/google'); | ||
|
||
const User = require('../db/models').User; | ||
const secrets = require('./secrets'); | ||
const User = require('../models').User; | ||
|
||
module.exports = (passport) => { | ||
const db = require('../models'); | ||
const Google = require('./passport/google'); | ||
|
||
const sequelize = db.sequelize; | ||
|
||
passport.serializeUser(function(user,done) { | ||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser(function(id, done) { | ||
User.findById(id, (err, user) => { | ||
done(err, user); | ||
}); | ||
|
||
User.findById(id) | ||
.then(user => { | ||
done(null, user); | ||
}) | ||
.catch(err => { | ||
if (err) throw err; | ||
}) | ||
}); | ||
/////////////////////////////// | ||
/* AUTHENTICATION STRATEGIES */ | ||
/////////////////////////////// | ||
Google(passport, User, secrets.google); | ||
Google(passport, secrets.google); | ||
}; |
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,23 @@ | ||
module.exports = { | ||
"development": { | ||
"username": process.env.PSQL_USERNAME, | ||
"password": process.env.PSQL_PASSWORD, | ||
"database": process.env.PSQL_DATABASE, | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"test": { | ||
"username": "root", | ||
"password": null, | ||
"database": "database_test", | ||
"host": "127.0.0.1", | ||
"dialect": "mysql" | ||
}, | ||
"production": { | ||
"username": "root", | ||
"password": null, | ||
"database": "database_production", | ||
"host": "127.0.0.1", | ||
"dialect": "mysql" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
'use strict' | ||
const SubscriberModel = require('../db/models').Subscriber; | ||
const SubscriberModel = require('../models').subscriber; | ||
|
||
module.exports = function(req, res) { | ||
const subscribers = req.body.subscribers; | ||
const fields = req.body.fields; | ||
module.exports = function(req, res) { | ||
const subscribers = req.body.subscribers; | ||
const fields = req.body.fields; | ||
|
||
console.log("got new subscribers: "); | ||
console.log(subscribers); | ||
console.log(fields); | ||
|
||
subscribers.forEach(subscriber => { | ||
|
||
SubscriberModel.find({email:subscriber.email}, (err, doc) => { | ||
if (err) throw err; | ||
if (doc.length) { | ||
// User exists! Do not save doc | ||
res.send({ | ||
status: 'error', | ||
message:'This email already exists' | ||
}); | ||
} else { | ||
let newSubscriber = new SubscriberModel(); | ||
newSubscriber.email = subscriber.email; | ||
newSubscriber.save(err => { | ||
if (err) throw err; | ||
}); | ||
} | ||
}) | ||
}); | ||
// -> use schema + add all the subscribers + field types to the database | ||
subscribers.forEach(subscriber => { | ||
SubscriberModel.findOne({ | ||
where: { | ||
email:subscriber.email | ||
} | ||
}).then(email => { | ||
if (email) { | ||
res.status(400) | ||
.send({ | ||
status: 'error', // Redundant | ||
message:'This email already exists' | ||
}); | ||
} else { | ||
SubscriberModel.create({ | ||
email: subscriber.email | ||
}).then(() => { | ||
res.status(201) | ||
.send({ | ||
status: 'success', // Redundant | ||
message: `${subscriber.email} added succesfully` | ||
}); | ||
}); | ||
} | ||
}) | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,36 +1,43 @@ | ||
'use strict' | ||
const _ = require('lodash'); | ||
const Settings = require('../db/models/index').Settings; | ||
const Settings = require('../models').settings; | ||
|
||
|
||
module.exports = function(req, res) { | ||
const settingsToChange = _.pickBy(req.body); | ||
|
||
// Exit if there are no settings to change | ||
if (_.isEmpty(settingsToChange)) { | ||
res.send({ | ||
type: 'error', | ||
res.status(400) | ||
.send({ | ||
type: 'error', // Redundant | ||
message: 'SES credentials form was empty' | ||
}); | ||
return; | ||
} | ||
|
||
// Should eventually refactor this to use findOneAndSave | ||
Settings.findOne({}, {}, (err, settings) => { | ||
if (err) throw err; | ||
/* | ||
Previous model needs to be refactored. Code left below for reference. | ||
*/ | ||
} | ||
|
||
// Create default settings if none exist | ||
if (!settings) { | ||
settings = Settings(settingsToChange); | ||
} else { | ||
_.keys(settingsToChange).forEach((setting) => { | ||
settings[setting] = settingsToChange[setting] | ||
}); | ||
} | ||
/* | ||
// Should eventually refactor this to use findOneAndSave | ||
Settings.findOne({}, {}, (err, settings) => { | ||
if (err) throw err; | ||
settings.save((err) => { | ||
if (err) throw err; | ||
res.json({}) | ||
// Create default settings if none exist | ||
if (!settings) { | ||
settings = Settings(settingsToChange); | ||
} else { | ||
_.keys(settingsToChange).forEach((setting) => { | ||
settings[setting] = settingsToChange[setting] | ||
}); | ||
}) | ||
} | ||
} | ||
settings.save((err) => { | ||
if (err) throw err; | ||
res.json({}) | ||
}); | ||
}) | ||
*/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Oops, something went wrong.