-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(config): Local environment configurations #1011
Conversation
An example of when a Mongoose upgrade causes database connectivity to break.. #1010 |
@@ -14,6 +14,13 @@ module.exports = { | |||
pass: '' | |||
} | |||
}, | |||
testDb: { |
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.
why testDb
?
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.
@ilanbiala Are you questioning the name? Or the purpose?
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.
Name
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.
what would be a better name?
We need to differentiate between the dev database, and test database. Or were specifically asking about the name? I couldn't think of anything better. |
I know we're having issues with Mongoose version support. However, this PR doesn't curtail those issues. This can help workaround the issues for a user running the app locally though. This PR is more for a convenience/support feature during local development. |
@mleanos this just adds another database to the local env. What does that really offer? |
@ilanbiala It doesn't just add any other database to the local env config. It offers the ability to specify a database that will be used by the Test env; other than a local database. The reasoning for this addition, is the same as why the There may even be cases where a user would want to test multiple databases, that reside in remote locations. This would offer that. The alternative would be to have the user manually modify the Test env config settings, or env variables. The reason why the database used in the Test env needs special handling, is because the local.js config isn't merged with the current env config. |
@mleanos doesn't it make more sense to fix that rather than add another field to circumvent that? |
@ilanbiala I realize I had a typo in my last comment. It should have read.. "... is because the local.js config isn't merged with the Test env config." This is why the test database would need special handling. Maybe this is a better explanation of what I'm trying to accomplish here... Currently, the Development, and Test, environment configs have a field called For someone that doesn't have a local instance of mongodb, or wants to connect to a remote db host (like MongoLab), they would need to set a environment variable. Having to manage the local environment variables is a cumbersome task & slows development. Thus, why the local.js was setup to allow the So what I'm proposing is to provide the same exact functionality for the Test environment database setting. However, we can't simply use the |
344e77e
to
3fd409a
Compare
@mleanos I'm still getting lost in what this is trying to accomplish, maybe try simplifying with an example? |
@ilanbiala Let's say you're developing on your local machine.. If you are actively testing/developing, using A user must either have an environment variable set, or a local instance of mongodb. Even if the user does have a local instance of mongodb, they may want to periodically/actively switch to a remote database, or even a different local instance (different database by name). By adding a setting in config/env/local.js that will be used for to connect to the mongodb when The example setting is in this PR, in config/env/local.example.js |
} else { | ||
// Check if we have a local.js custom/local environment. If one exists, we need to check for a test database setting | ||
// that will override the current config object's "db" field. Given the fact that newer versions of MongoDB are | ||
// deprecating the MONGODB-CR authentication. In such cases, mongoose won't connect without the "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.
Aside: This part of the comment doesn't really pertain to this.
What's wrong with having the default db be localhost and then you never have to worry about not having a 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.
@ilanbiala What if the user doesn't have mongodb installed locally? localhost won't exist.
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.
@mleanos I don't see why that wouldn't be something that we could ask instead of all this. I get what this is doing now, but I'm really not fond of how we go about it, and I think it's too much of a stretch when you can just avoid the issue.
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.
@ilanbiala It's not about avoiding an issue, or not. There are many use cases that this may useful for.
Think of the reason why we have the db
setting in local.js for use when the app ran with Development. Now apply that same reasoning to someone running the app with Test env.
d9d03c3
to
a8e90ae
Compare
@mleanos I think this PR wasn't described properly so it took me some time to figure out what you're after. You basically saying that you'd like to specify custom test environments for both test and development? so that when you are running your Seems to me like a valid point and useful in my cases as well. I would even extend it to also override the production development environment if someone wishes to do so in local.js and not commit that file to git. |
@lirantal I apologize for the confusing commit message, and the branch name :| It was created when I thought the sky was falling with Mongoose ;) I realize it may have been why this PR is confusing. And yes, I think you get my point. I want the same functionality that @jloveland had a good idea on restructuring local.js. Something like
We would need a function in config.js that properly overrides any settings in local.js for the current NODE_ENV. Is that what you were driving at? |
@mleanos sounds like a good idea, or do you think it will be more organized to have: |
I think I like your idea of breaking them into their own files. It seems like it would be easier for a user to manage that way. Thanks a bunch! Glad you thought of it, cuz it didn't even cross my mind :) |
Cool. |
+1 for local.js files to specify different configs for each environment. |
+1 sounds like a good idea, many people when using CF have a dev, test, and production versions deployed as well. |
I'm not really too fond of having many files for one environment based on NODE_ENV, but I can't think of a much better way. |
a8e90ae
to
d41bf08
Compare
@lirantal @ilanbiala I have updated this PR per our discussion. I've also squashed down to one commit to avoid any confusion, since the previous commits are no longer applicable. I'm wondering if we could get this into 0.4.2. The only possibility of a breaking change is that a user's previous local.js file will not be picked up by this change. That seems very minor, IMO. WDYT? |
e9fddf6
to
6fe68e7
Compare
@@ -22,6 +22,7 @@ public/dist/ | |||
uploads | |||
modules/users/client/img/profile/uploads | |||
config/env/local.js | |||
config/env/local-*.js |
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.
@jloveland What about the existing local.example.js file that we do want to commit into the repo?
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.
@codydaig, apologies, you are correct because the grunt copy function needs the local.example.js
@jloveland Thank you for the review, and for being the catalyst that got this implementation conceptualized :) I originally thought that the additional local-ENV files should be created as well. Since the Even though there's no tangible need for the We definitely will need to add some documentation for this. I tried putting as much into local.example.js as I could, but the gh-pages will need it too. |
SGTM! |
LGTM. |
LGTM |
Awesome, we'll merge once we release 0.4.2 and start working on 0.5.0 |
SGTM. Thanks @ilanbiala! |
4c97028
to
ba3a4e3
Compare
Looks like the build is failing on [email protected] Once 0.4.2 is released, I'll look at this further. |
Sounds good. |
@lirantal This is ready to be merged, now that we have 0.4.2 released. |
Indeed, I'll close and re-open so we can re-run CI to make sure everything is ok. |
@mleanos Can you rebase too verify that everything is up too date and working? |
@mleanos build fails on node v4 test. |
Ok. Thank you. I'll rebase, and test again. |
Adds the ability to configure multiple env configurations, for the various NODE_ENV's. These configs can be used to override the current configuration, using the appropriate local-NODE_ENV.js file that the user has defined. Updated the local.example.js comments to be clear on the usage. Added config/env/local-*.js to gitignore. Updated the copy:localConfig Grunt task to copy local.example as local-development.js, since we're no longer going to use local.js.
ba3a4e3
to
6d74474
Compare
LGTM |
feat(config): Local environment configurations
Thanks guys! To anyone that uses this, let me know how it's working out with your development flow. I'm curious to know from other developers perspective. Now I can get rid of all my crazy logic/functions in my local.js file :) |
EDIT: 10/29/2015
This PR has changed quite a bit, and originally was not properly described. Please see the below commit, and discussion.
Enables the setting of the test database configuration inside of the local environment config. If this setting is present, then it will override the db setting in the Test environment config. This will compliment the already existing
db
setting in local.js.I've also added environment variables to Production, Test, and Development:
process.env.MONGO_USER
process.env.MONGO_PASS
This is both an enhancement, and support feature. Newer versions of MongoDB are deprecating MONGODB-CR authentication. Going forward it is best practice to provide the
user
&pass
options with the mongooseconnect
method.This also enhances the experience of a meanjs user, by providing an easy way to manage their connections between dev & test databases. For someone (like me) using MongoLab, the ability to pass the connection options to mongoose will save a lot of time during development/testing.
For me, the way I have been going about managing my testing database is by manually setting
MONGOLAB_URI
to my URI; which includes the user & pass. However, once Mongoose is upgraded to a version that no longer supports this, I would lose the ability to connect my mean app to my Test database.I set this PR as a WIP because I anticipate much debate about this implementation. However, I would really like to get this conversation going. We can't avoid Mongoose upgrades for too long.