Skip to content

ziedtuihri/SaaS_Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conversion of a MySQL App to Multi-Tenant

in my file Generate_multiTanentMysql.php i do all steps to convert a simple app to SAAS app with PHP script

A Solution Design Pattern

    The chosen solution involves the following:
  • Creating a database user for each tenant
  • Renaming every table to a different and unique name (e.g. using a prefix ‘someprefix_’)
  • Adding a text column called ‘id_tenant’ to every table to store the name of the tenant the row belongs to
  • Creating a trigger for each table to automatically store the current database username to the id_tenant column before inserting a new row
  • Creating a view for each table with the original table name with all the columns except id_tenant. The view will only return rows where (id_tenant = current_database_username)
  • Only grant permission to the views (not tables) to each tenant’s database user
  • Then, the only part of the application that needs to change is the database connection logic. When someone connects to the SaaS, the application would need to:
  • Connect to the database as that tenant-specific username

Background

Many years ago I was faced with the challenge to take a legacy web application intended for one customer (tenant) and turn itinto a multi-tenant SaaS application. The app itself was large, but not particularly complex. It used around 60 tables in a MySQL database and did not use views,triggers, or stored procedures. At the start, the application was accessible using a single domain. The request was to alloweach “tenant” to access the software from a different domain without any sharing of data. or my solutions Zied Tuihri is with a session with the name of tenant to connect with the string value in database .


How to convert your app with the new MySQL Multi-Tenant

Setting database dynamically according to sub-domain URL with multi host for evry user 'tenant'

Setting database dynamically according to a ssession is my solution @ziedtuihri with one host

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published