Reputation: 2149
I want to change data base from inbuild H2 to Mysql database in grails , Grails documentation says change in Datasource.groovy file will change the database but it is working only for my development environment but not for test environment , Even i have tried removing the complete Datasource.groovy file and deleted the database from mysql and try to run the test it just succeeds ,so can any body help what is the mistake i am doing .
I have went almost all the question in stackoverflow every body suggesting to change in DataSource.groovy file but it doesn't work for me .
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "root"
logSql =true
password = "root"
properties {
maxActive = -1
minEvictableIdleTimeMillis = 1800000
timeBetweenEvictionRunsMillis = 1800000
numTestsPerEvictionRun = 3
testOnBorrow = true
testWhileIdle = true
connectionProperties = "[autoReconnectForPools=true]"
testOnReturn = true
validationQuery = "SELECT 1"
}
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://127.0.0.1/devenvi"
}
}
test {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://127.0.0.1/testenvi"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://127.0.0.1/prodenvi"
}
}
}
Upvotes: 0
Views: 1350
Reputation: 2382
1) Make sure you have a section in DataSource.groovy for your test environment, example:
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
environments {
test {
dataSource {
url = "jdbc:mysql://liveip.com/liveDb"
// other environment-specific settings here
}
}
}
2) make sure you are doing a build that specifies the test environment:
/path/to/grails -Dgrails.env=test war
will generate project.war file that will use the appropriate environment setting in your DataSource.groovy file
Upvotes: 2