I'd like to make my Bootstrap dependant on the createdb property in the grails DataSource.groovy file. When the setting is 'create', new Master Data should be generated, if the setting is 'update', none.
I've found GrailsDataSource in the Grails API which also has a method getCreateDb, but I don't know how to access it from the Bootstrap for the respective Bootstrap environment.
The up-to-date way to obtain dbCreate property is injecting 'grailsApplication' to BootStrap.groovy:
def grailsApplication
if(grailsApplication.config.dataSource.dbCreate == 'create'){
...
}
ApplicationHolder is now deprecated and I couldn't get it to work.
Hope it helps someone.
The easiest way is probably to just check the value of dbCreate from the config, like so:
import org.codehaus.groovy.grails.commons.ApplicationHolder
if (ApplicationHolder.application.config.dataSource.dbCreate == "create") {
...do create stuff...
} else if (ApplicationHolder.application.config.dataSource.dbCreate == "update") {
...do update stuff...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With