Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database config does not work for environments #16

Closed
konstantinzolotarev opened this issue Sep 7, 2016 · 8 comments
Closed

Database config does not work for environments #16

konstantinzolotarev opened this issue Sep 7, 2016 · 8 comments

Comments

@konstantinzolotarev
Copy link
Collaborator

Issue Description

I have a default config in config/database.js and a different config in config/env/testing.js. When I set the environment to testing the database configuration from testing.js is not used. When I remove the stores and models objects from database.js trails just does not detect any database configuration.

database.js:

module.exports = {

  /**
   * Define the database stores. A store is typically a single database.
   *
   * Set production connection info in config/env/production.js
   */
  stores: {

    mongodbstore: {
      // should be 'create' or 'drop'
      migrate: 'create',
      uri: 'mongodb://localhost:27017/jungo',
      options: {}
    }
  },

  models: {
    defaultStore: 'mongodbstore',
    migrate: 'create'
  }
}

testing.js:

'use strict'

module.exports = {

  trailpack: {
    disabled: [
      'repl'
    ]
  },
  database: {
    stores: {
      mongodbstore: {
        migrate: 'create',
        uri: `mongodb://${process.env.MONGO_HOST}:27017/jungo`,
        options: {}
      }
    },
    models: {
      defaultStore: 'mongodbstore',
      migrate: 'create'
    }
  }
}

Environment

  • node version: 6.4.0
  • version: 1.0.0-beta-1
  • operating system: OSX 10.10.5

Manually updated to 1.0.4 as npm did not detect it, didn't help to solve the issue. The ORM I use is mongoose with version 0.4.1. of trailpack-mongoose.

@sschimmel +

@konstantinzolotarev
Copy link
Collaborator Author

@sschimmel just tested on local env.
Configuration wokring fine.

Did you run app with NODE_ENV=testing ?

@sschimmel
Copy link

Check to see if I have a database.js file and indeed in node_modules/trailpack-mongoose/config is a file named database.js. I'm on the most recent trailpack-mongoose (0.4.1).

Application is started with NODE_ENV=testing.

In node_modules/trailpack-mongoose/config/database.js I only see models being exported. Is it possible to add a store there? That's what I've done in the env config.

@sschimmel
Copy link

Defining a second store in config/database.js doesn't work either. Trails then tries to connect to both stores of which one fails as that config isn't valid for the environment we're in.

@konstantinzolotarev
Copy link
Collaborator Author

@sschimmel Could you please show your app somehow ?

@sschimmel
Copy link

What parts are you interested in? I can make a gist of those files.

@konstantinzolotarev
Copy link
Collaborator Author

@sschimmel Could you please try to run my sample from here:
https://github.com/konstantinzolotarev/trails-env-config-test

Just run npm start and exec this from trails console
app.orm.Test.create({ question: 'test' }).then(console.log).catch(console.log)

@sschimmel
Copy link

Both work however the testing environment is also using the test3 database from development and not the temp database as is specified in the configuration file.

info: All trailpacks are loaded.
info: ---------------------------------------------------------------
        Thu Sep 08 2016 11:20:16 GMT+0200 (CEST)
        Basic Info
          Application       : test
          Application root  : http://0.0.0.0:3000
          Version           : 0.0.0
          Environment       : development
info: ---------------------------------------------------------------

trails > app.orm.Test.create({ question: 'test' }).then(console.log).catch(console.log)
Promise { <pending> }
trails > { __v: 0, question: 'test', _id: 57d12d511c88a70e2bafabd7 }
info: All trailpacks are loaded.
info: ---------------------------------------------------------------
        Thu Sep 08 2016 11:21:37 GMT+0200 (CEST)
        Basic Info
          Application       : test
          Application root  : http://0.0.0.0:3000
          Version           : 0.0.0
          Environment       : testing
info: ---------------------------------------------------------------

trails > app.orm.Test.create({ question: 'test' }).then(console.log).catch(console.log)
Promise { <pending> }
trails > { __v: 0, question: 'test', _id: 57d12db1831bba0e2ebbca54 }

image

@konstantinzolotarev
Copy link
Collaborator Author

@sschimmel ok. Thank you. Will look into this again. With updated node version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants