2

Right now we have a DataSource.groovy file in conf for our grails app. It has settings like this...

   development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/mydb?useUnicode=yes&characterEncoding=UTF-8"
            username = "user"
            password = "password"
        }
    }

When different developers will have different host/username/passwords for their database what is a good way to swap out per-developer settings without changing this file and attempting to remember to not check in the changes to source control? As the application grows so will the number of settings that need to be changed on different developer's machines.

doelleri
  • 19,232
  • 5
  • 61
  • 65
benstpierre
  • 32,833
  • 51
  • 177
  • 288

1 Answers1

2

I set up my development environment to look for environment variables holding the username and password, which are created by the developer before running grails run-app.

    development {
        dataSource {
          //dbCreate = "update" // one of 'create', 'create-drop','update'
            url = "jdbc:oracle:thin:@myserver:1521:SID"
            username = System.env.grails_user
            password = System.env.grails_password
            dialect = org.hibernate.dialect.OracleDialect
        }
    }

To prevent confusion, I put the following comment block at the beginning of the file (we develop in Windows).

/***********************************************************************
 * The development and test environments expect to find the database
 * username and password in the following system environment variables.
 *
 *   grails_user
 *   grails_password
 *
 * Before trying grails run-app or grails test, be sure to set the
 * variables.  In Windows, you can type the following.
 *
 *   set grails_user=<your username>
 *   set grails_password=<your password>
 *   grails run-app
 *
 * The system will remember the password as long as you don't close the
 * cmd window.
 *
 **********************************************************************/

It's a little bit of a nuisance, but it is worth some trouble to keep passwords out of our source code and revision control system.

Big Ed
  • 1,056
  • 9
  • 20