Hello folks. I hope everyone is doing well in this trying time. In this blog, I will talk about an important topic - cloud computing and SaaS (Software as a service), also known as Multi-tenancy.
Multi-tenancy is about more than just a SaaS implementation: a lot of enterprises wanted to isolate their data based on their business units and their domain verticals.
First I would like to take a moment to explain what is multi-tenancy, for those of you who are not familiar with it.
The term “multi-tenancy” refers to a software architecture in which a single instance of software runs on a server and serves multiple tenants. For more clarity, I would recommend everyone to go through the following wikipedia entry Multitenancy — Wikipedia
In general, we have two options in achieving multi-tenancy in any platform.
- Shared database for all the tenants.
- Separate database or Schema for each tenant.
We are going to discuss option 2 - Separate database or Schema’s for each tenant.
The term “schema” refers to the organization of data as a blueprint of how the database is constructed — wikipedia
Manipulating the Database
We will be using PostgreSQL as a backend in order to do the database manipulation.
There has to be an interface for an admin to create the tenants dynamically. Through this interface, the admin can name the tenants and initiate the database creation at run-time.
We will achieve this in four steps, a microflow will invoke the Java action, which in turn invokes the batch file, which in turn invokes the sql script file.
- Step 1 - Mendix
- Step 2 - Java Actions
- Step 3 - Batch file (Windows)
- Step 4 - SQL Script file.
We will need the help of a Marketplace module to support this implementation, the Database connector. This will help retrieve the data from all the external data sources.
Create a microflow and call a java action
Assume that the NewSchema object will be created and passed as an input parameter to this microflow, following with the piece of java code in the java action by specifying the file path and batch file name.
This piece of code under executeAction() method invokes the batch file and the batch file script should look like as follows.
The sql script file would have the script as follows.
So, with these mechanisms you would be able to create the separate database or schema for each tenant.
We will see how the user will post and retrieve data from the created database or schema in the next part.
Until then. Stay safe, stay happy, stay foolish.
Mendix World 2021 | Bring your app development A-team together September 7–9, 2021
As if you need convincing… in a global community of makers who want to learn from one another by exploring what’s…
Tracks | Mendix World 2021
Handcraft your agenda before Mendix World kicks off this year. Browse 85+ sessions across 8 tracks tailored to your…
From the Publisher -