SaaS- Tenant Specific Lookup Data in Shared Database

前端 未结 4 1955
野性不改
野性不改 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:14

    This is the design I would then use.

    Games

    Id
    GameName
    IsTenantSpecific
    SomeGameSpecificColumn
    

    TenantGames

    GameId
    TenantId
    SomeTenantSpecificColumn
    AnotherTenantSpecificColumn
    

    Then you can query that table in a Join with:

    ...
    FROM
        Games
        INNER JOIN UserGames ON
            UserGames.GameId = Games.Id
        LEFT JOIN TenantGames ON
            TenantGames.GameId = Games.Id
    WHERE
        TenantGames.TenantId = @tenantId OR
        (
            TenantGames.TenantId IS NULL AND
            IsTenantSpecific = 0
        )
    

    Game specific fields can be put in the Games table. Tenant specific fields can be added to the TenantGames table, and those fields will be NULL if it is not a tenant specific customization.

提交回复
热议问题