mkobel
mkobel

Reputation: 346

How to work with grails and multiple postgresql database schemata

Sometimes we have one application which uses multiple database schemata.

E.g. There is a table company1.someTable which looks exactly like company2.someTable. But some users have access to company1., others to company2. oder both.

Is there an easy way to tell grails to work with a database like this and let the user select the schema?

Upvotes: 0

Views: 775

Answers (1)

Adam Brokes
Adam Brokes

Reputation: 161

You could try Datasources plugin.

http://www.grails.org/plugin/datasources

I have managed to connect two different mysql databases (postgres should be the same).

In grails project run command:

grails install-plugin datasources

Create file conf/Datasources.conf, which will hold the second schema (the default is still in Dataseource.conf)

for example:

datasources = {

datasource(name: 'wadmin') {
    driverClassName('com.mysql.jdbc.Driver')
    dbCreate("update")
    url("jdbc:mysql://localhost/wadmin-test")
    username("xx")
    password("xx")
    // here you will write list of classes in particular schema
    domainClasses([cz.webarchiv.wadmin.Curator, cz.webarchiv.wadmin.Publisher])
    dialect(org.hibernate.dialect.MySQL5InnoDBDialect)
    pooled(true)
    environments(['development'])
}

}

Mind the small "s" letter in datasources.

Hope this helps.

Upvotes: 1

Related Questions