mysql - Grails: changing dataSource url at runtime to achieve multi tenant database separation -


i'm building multi tenant application grails , want keep separate databases. need change url dynamically @ runtime point gorm different database.

i have front-end acting balancer distributing requests cluster of backend hosts. each backend host runs grails 2.3.5 instance , mysql-server several databases (one per tenant). change datasource dynamically gorm can access domain entities on right database.

any ideas ?

thanks

you can configure multiple data source in datasource.groovy, have in blog.

in domains: add data source domain can interact, eg.,

static mapping = {     datasources(['datasource1', 'datasource2']) } 

or "all" datasources, eg.,

static mapping = {     datasource 'all' } 

and can make queries data source name want get/set data, eg.,

def userclass = user.class user user = userclass.datasource1.findbyname('username') 

ref:- multipledatasources, querying on multiple datasource in grails


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -