I started working on a multi-tenant branch and was interested in feedback, but I’m not sure it’s ready for a pull-request.
You can see the diff at on Github, but it’s mostly just integrating Hibernate Multi-tenancy.
It’s able to route the correct database by using the requested hostname; so for example if your domain is hospital.com and you point clinic1.hospital.com and clinic2.hospital.com to the same openmrs server, then the requests would be routed to the same mysql server, but use clinic1 or clinic2 databases depending on the hostname.
All “tenants” (clinic1&2 in the example) have to use the same modules, but can have different locations, concepts, and patients and users.
When the server starts up, one of the tenants is the “primary” tenant, or preferred, you would create a fresh openmrs database. This “primary” database name is specified in ‘connection.database_name’ and is used when openmrs is starting; so it will some of the global properties from that database.
Database updates are completed disabled. The thinking here is that since the core war & modules are shared by all tenants that upgrades would need to be coordinated across all tenants. My thought is that it would be a slower moving release cycle. When an upgrade is needed, one solution would be to copy the “fresh” database to a new instance and run the new core war & modules against that in a staging server (run multi-tenancy disabled so upgrades can run). Then use an offline tool like liquibase diff to create an upgrade script that could be applied to each of the databases and run at the same time.
While liquibase is disabled for core & modules, some modules use their module activator to make data changes. The module activators still run at startup but only against the “primary tenant” database. This is another reason to upgrade modules on a staging server and determine the changes and create a update script for each tenant. This may seems like a lot of work, but again, my thinking is that these would be focused run on stable long-term support versions and not organizations on the bleeding edge.
I tested most of the modules that come with the ref app and they seem to work in multi-tenant mode; i.e. they don’t cache things globally and use hibernate correctly.
My overall goal for working on multi tenancy is to work on a free hosting solution for hospitals and clinics that don’t want to put a big investment into hosting & operations. If we can host each OpenMRS distributions on a ‘beefy’ server in the cloud then it should be rather easy/low cost to add individual tenants.
I welcome any feedback / suggestions.