-
Notifications
You must be signed in to change notification settings - Fork 2k
Conversation
1eb79a1
to
1c6faff
Compare
I started on a bigger refactor of the Mongoose and Express app implementation. However, I scaled it back to just satisfy the Mongoose upgrade. We can discuss a bigger refactor in a separate issue and/or PR. Regarding the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few notes but otherwise looks really good!
Happy you figured out that issue with Mocha.
config/lib/mongoose.js
Outdated
}); | ||
if (cb) cb(connection.db); | ||
}) | ||
.catch((err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some ES6 here ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's ok?
Node.js >=6.4.0
can handle handle arrow functions. So why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to see bigger discussion about this, actually. This topic just came up at Trustroots so I might open an issue here just to get some food for thought.
I don't think it's a good idea to introduce mixed coding style in PR like this.
It's more annoying to me to see mixed style rather than old school JS.
I'd love to see meanjs move on to ES6 but it might be better done with some strategy and thought and build tools (eslint) could probably be upgraded first.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything you just said seems very reasonable to me. I'd like to discuss the introduction of ES6 as well. I think it started becoming a habit for me, since I'm using some features like arrow functions in my projects.
I'll remove my ES6 usage from this PR.
gulpfile.js
Outdated
mongoose.disconnect(function () { | ||
done(error); | ||
}); | ||
mongooseService.disconnect(done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost did this myself as well, but that error
being passed to gulp's done
isn't error from mongoose disconnect. It's the error object from Mocha.
Error thrown from disconnecting probably doesn't need to fail the whole gulp task? Dunno.
Perhaps that variable needs renaming so that it would be clear what's happening here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, good points. It did occur to me, for a moment, about the error
needing to be passed to the done. Then I think I just overlooked it. I'll change it to pass the Mocha error to the done
callback. I guess we can just log the error to the console, when the disconnect
fails; it would be a rare error in this case.
The name error
seems fine to me. It's clear what's going on since it's right there.
@@ -362,16 +359,17 @@ gulp.task('karma:coverage', function(done) { | |||
// Drops the MongoDB database, used in e2e testing | |||
gulp.task('dropdb', function (done) { | |||
// Use mongoose configuration | |||
var mongoose = require('./config/lib/mongoose.js'); | |||
var mongooseService = require('./config/lib/mongoose'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as earlier:
Is there any reason why this require
is inside the task and not on top of the gulp file with all the other dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If our Mongoose service is only being used in a couple places, why require
it at the global scope?
My understanding of how require
works, along with it's memory use, isn't great so maybe it doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I don't know more than you do. :-) I was just curious, I guess for now we can trust someone knew what they were doing when they placed it inside the task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amos added it way back in 0.4 release branch.
We can move it at the top if it makes sense now, but I think when Amos added it on 0.4 the mongoose.js worked differently from today, as in, just requiring it may have opened the database connection or instantiate models so that would explain why he would have wanted to limit it to the specific gulp tasks.
@@ -277,15 +277,15 @@ gulp.task('templatecache', function () { | |||
|
|||
// Mocha tests task | |||
gulp.task('mocha', function (done) { | |||
// Open mongoose connections | |||
var mongoose = require('./config/lib/mongoose.js'); | |||
var mongooseService = require('./config/lib/mongoose'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why this require
is inside the task and not on top of the gulp file with all the other dependencies?
@@ -23,7 +23,7 @@ var app, | |||
describe('Article Admin CRUD tests', function () { | |||
before(function (done) { | |||
// Get application | |||
app = express.init(mongoose); | |||
app = express.init(mongoose.connection.db); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This <3, I just couldn't figure out what was wrong before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a source of confusion to me too. I didn't see how the line above would work by just passing mongoose
, but eventually it made sense based on this: https://github.com/meanjs/mean/blob/master/config/lib/mongoose.js#L27. db
is a promise, no?
If these changes get merged then it's a moot point, I guess. Ideally, we need to refactor the Express & Mongoose implementations. As it stands, after we make the first connection, we're heavily relying on the fact that Mongoose is a singleton. This could be confusing, and probably not the best SOC design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup!
I guess https://github.com/lirantal/Riess.js might have quite a lot of it thought through already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that said I think it's a good idea to keep this to minimum to just get Mongoose upgraded and leave refactoring to a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. And indeed the returned value of the mongoose.js line 27 was just the db object being resolved with.
@lirantal Mikael and I discussed in his other PR that I would be taking this over. Once I get a couple things clarified from the review comments, I'll rebase and make the necessary changes. |
1c6faff
to
b4c3565
Compare
Looks good to me now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed one more minor thing.
user: '', | ||
pass: '' | ||
}, | ||
options: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove these also from the example config file?
https://github.com/meanjs/mean/blob/master/config/env/local.example.js#L23-L26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
b4c3565
to
1ed438f
Compare
@simison @lirantal I've rebased and squashed my commits. I also removed the |
@@ -119,7 +119,7 @@ describe('Article CRUD tests', function () { | |||
// Save the article | |||
articleObj.save(function () { | |||
// Request articles | |||
request(app).get('/api/articles') | |||
agent.get('/api/articles') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch @mleanos
@@ -11,7 +11,7 @@ var passport = require('passport'), | |||
/** | |||
* Module init function | |||
*/ | |||
module.exports = function (app, db) { | |||
module.exports = function (app) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could potentially break vertical modules that rely on it.
even with the changes in this PR for config/lib/mongoose.js
how would one be able to access the db instance?
the other alternative I can think of is if we set app.local.db or something like that which would expose the db connection where app is too.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that, sounds simple and straightforward. I didn't like at all trying to follow where db
is going around trough all those callbacks.
That said, this could also wait for more thorough restructuring of mongoose/db stuff as with promises etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In leaning towards agreeing with 'this can wait' but I wonder what projects built based on master version will do if db
is now not available for them and they wish to stay up to date...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should note the potential breaking change in the CHANGELOG.
Anyone merging from master should be aware of the changes, and it seems like it would be easy for them to add back the db
in their exports where they rely on it. Adding app.local.db
wouldn't be a difficult task either.
I'm a bit skeptical that many use cases would arise that would require someone to rely on accessing the db
instance from server-side config/controllers.
I'm not opposed to adding db
back to all the callbacks though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah which is why I'm not totally against removing it.
so let's keep this PR as is and see how the mongodb refactoring continues on. I'm ok with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'm fine with that as well.
@lirantal Are you still waiting on changes before you can approve this? |
Nope, I'm good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found another small issue.
@@ -24,25 +25,28 @@ module.exports.connect = function (cb) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove var _this = this;
as it's never used (weird how eslint didn't warn about this?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. The ESLint rule no-unused-vars is turned off, probably because there are a lot of ESLint errors generated from this rule in our tests and other places :/ That can be addressed in a separate PR.
config/lib/mongoose.js
Outdated
if (cb) cb(db); | ||
} | ||
}); | ||
if (cb) cb(connection.db); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer using callback
instead of cb
just to keep it all the same and I dislike abbreviations in coding (just needs extra thinking when reading it), but this isn't a biggie. :-)
Upgrades Mongoose to 4.11.1 Updates Mongoose connection implementation to accommodate deprecated features & connection options. Also, updates the Gulp Mocha tasks to reflect changes to the Mongoose implementation. Fixes tests to get the database from the existing Mongoose singleton. Derives from changes in meanjs#1816 Closes meanjs#1814
1ed438f
to
8940173
Compare
Yep, I'm good. |
LGTM! Feel free to merge. |
feat(config): Mongoose 4.11 upgrade (meanjs#1818)
Upgrades Mongoose to 4.11.1 Updates Mongoose connection implementation to accommodate deprecated features & connection options. Also, updates the Gulp Mocha tasks to reflect changes to the Mongoose implementation. Fixes tests to get the database from the existing Mongoose singleton. Derives from changes in meanjs#1816 Closes meanjs#1814
Upgrades Mongoose to
4.11.14.11.3Updates Mongoose connection implementation to accommodate deprecated
features & connection options.
Also, updates the Gulp Mocha tasks to reflect changes to the Mongoose
implementation.
Fixes tests to get the database from the existing Mongoose singleton.
Derives from changes in #1816
Closes #1814