16.1 Multi-Tenancy GORM
GORM supports Multi-tenancy and integrates with Micronaut.
To use Micronaut and GORM multitenancy capabilities you must have the multitenancy-gorm
dependency on your classpath. For example in build.gradle
:
build.gradle
compile "io.micronaut.configuration:micronaut-multitenancy-gorm"
GORM is a powerful Groovy-based data access toolkit for the JVM with implementations several data access technologies (Hibernate, Neo4j, MongoDB, GraphQL …).
GORM supports the following different multitenancy modes:
DATABASE
- A separate database with a separate connection pool is used to store each tenants data.SCHEMA
- The same database, but different schemas are used to store each tenants data.DISCRIMINATOR
- The same database is used with a discriminator used to partition and isolate data.
In order to use GORM - Multitenancy you will need to configure the following properties: grails.gorm.multiTenancy.mode
and grails.gorm.multiTenancy.tenantResolverClass
.
Micronaut support for Multi-tenancy integrates with GORM.
The following table contains all of the TenantResolver implementations that ship with `multitenancy-gorm
module and are usable out of the box.
name | description |
Resolves the current tenant from an HTTP cookie. | |
Resolves against a fixed tenant id | |
Resolves the current tenant from the request HTTP Header. | |
Resolves the current tenant from the authenticated username. | |
Resolves the current tenant from the HTTP session. | |
Resolves the tenant id from the subdomain. | |
Resolves the tenant id from a system property. |
You will need to add something like the following snippet to your app configuration:
grails:
gorm:
multiTenancy:
mode: DISCRIMINATOR
tenantResolverClass: 'io.micronaut.multitenancy.gorm.PrincipalTenantResolver'
Please, read GORM Multi-tenancy documentation to learn more.