SaaS- Tenant Specific Lookup Data in Shared Database

前端 未结 4 1954
野性不改
野性不改 2021-01-28 06:17

I am developing multitenant SaaS based application and going with Shared Database for storing all the tenant records with help of TenantId column.

Now the problem is i h

4条回答
  •  面向向阳花
    2021-01-28 07:05

    We have a saas based database and we keep common data and tenant data in the same table.

    Concept

    GamesTable
    
        Id NOT NULL
        TenantId NULL
        GameName NOT NULL
        Add a unique key for TenantId and GameName
    
    • if TenantId is NULL you know it is common data
    • if TenantId is NOT NULL you know it belongs to a specific tenant and who exactly.

    "Is there any other DB design which allows me to do mix both common master data and tenant master data with JOIN?"

    Yes

    SELECT *
      FROM GamesTable where TenantId = 'your tenant id'
      UNION
    SELECT *
      FROM GamesTable where TenantId IS NULL  -- common 
    

提交回复
热议问题