multi-tenant-core and uniqueness-constraints

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

multi-tenant-core and uniqueness-constraints

Konstantinos Kostarellis
Is the multi-tenant-core plugin taking care of extending the unique contraint on a domain class ?

If used in multi-tenant ( multi-tenant mode ) uniqueness constraints can't obviously work the same way. They would need
to be spawned over the "tenantId" and the key declared as unique in the first place.

I guess this is something a developer needs to take care of ? Couldn't find anything about it in the plugins documentation.

thnx,
 Kosta

Reply | Threaded
Open this post in threaded view
|

Re: multi-tenant-core and uniqueness-constraints

Kimble
The plugin won't do this for you. I'm not sure what the best solution would be in a multi database scenario. If you're using a single database you can add a unique constraint including tenantId, something like:

static constraints = {
    username unique: "tenantId"
}

I wrote some code to automatically add tenantId to all unique constraints in the multi-tenant-single-db fork, but I found it to be too intrusive and dropped it.
 - Kim A. Betti
Have a nice day!
Reply | Threaded
Open this post in threaded view
|

Re: multi-tenant-core and uniqueness-constraints

scryan
Since the plugin was originally designed to be non invasive it should run against you normal constraints with nothing special added in the multi database case.  There have been changes in the recent plugin to remove that capability from the single database model.  If you are in the multi database mode just design your database as you normally would and when you add the plugin nothing will change.

WE will have re visit the single database mode and understand why the tenant id was removed from the indexes.


Scott Ryan
CTO
Denver, Colorado  USA
(303) 263-3044

On Mar 14, 2011, at 8:12 AM, Kimble wrote:

The plugin won't do this for you. I'm not sure what the best solution would
be in a multi database scenario. If you're using a single database you can
add a unique constraint including tenantId, something like:

static constraints = {
   username unique: "tenantId"
}

I wrote some code to automatically add tenantId to all unique constraints in
the multi-tenant-single-db fork, but I found it to be too intrusive and
dropped it.

-----
- Kim
Have a nice day!
--
View this message in context: http://grails.1312388.n4.nabble.com/multi-tenant-core-and-uniqueness-constraints-tp3353454p3353940.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: multi-tenant-core and uniqueness-constraints

Kimble
The plugin should probably not do anything in single database mode as there are multiple valid use cases. Lets say you have "User" model with a "username" field. In some use cases you'll require username to be unique across all tenants sharing the database, while in anther use case it might be enough that the username is unique per tenant.

Database indexes should be created with the most common queries in mind.
 - Kim A. Betti
Have a nice day!
Reply | Threaded
Open this post in threaded view
|

Re: multi-tenant-core and uniqueness-constraints

Konstantinos Kostarellis
I'd think if you want uniqueness between tenants, you simply shouldn't annotate that domain class. Don't know if that would fit for all use cases, though.
Anyways, i just wanted to make sure I do it the right way. Thnx for the clarification on this. 

Besides IMHO I find it pretty reasonable to have to take care of the uniqueness constraints.
But it should be mentioned explicitly in the docs <<< could be some tripping hazard for a starter.

The Drawback is that you can't switch easily between single and multi db mode. Got to decide at the start. 

One more question (little bit offtopic): Is it somehow possible to make searchable / elasticsearch work correctly with multi-tenant ? 
In the basic configuration it's not, as searchable works on the lucene index, where multi-tenant can't filter the query.

thnx,
   Kosta


On Mon, Mar 14, 2011 at 3:35 PM, Kimble <[hidden email]> wrote:
The plugin should probably not do anything in single database mode as there
are multiple valid use cases. Lets say you have "User" model with a
"username" field. In some use cases you'll require username to be unique
across all tenants sharing the database, while in anther use case it might
be enough that the username is unique per tenant.

Database indexes should be created with the most common queries in mind.

-----
 - Kim A. Betti
Have a nice day!
--
View this message in context: http://grails.1312388.n4.nabble.com/multi-tenant-core-and-uniqueness-constraints-tp3353454p3354000.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email