duanliang1019 2013-05-01 07:01
浏览 226

如何为多租户SaaS产品设计有效的数据库?

My team and I are building a SaaS product which is to be used by multiple businesses across the world. To put it simply, our software does some basic accounting for them and alerts them if some document is due for renewal.

The problem is, there may be just 3 such documents for each such company in India but 4 in Sri Lanka and 7 in Singapore. And each field may be named differently. For example, the three fields may be called "Drivers' License", "Insurance", "Permit" in India but they may be called "XYZ","XXYZ" and "XZY" in Singapore.

What is the best and most effective way to implement such features using MySQL. Let's say I can cap the number of such columns at 5. Also, I do not want to use NoSQL for this project.

We're using PHP running on CodeIgniter and we plan to deploy on Engineyard.

  • 写回答

2条回答 默认 最新

  • duanmian1085 2013-05-01 07:27
    关注
    CREATE TABLE Countries (
      CountryCode CHAR(2) PRIMARY KEY,
      CountryName VARCHAR(255),
    );
    
    CREATE TABLE Companies (
      CompanyID   SERIAL,
      CountryCode CHAR(2) REFERENCES Countries (CountryCode),
      -- etc.
    );
    
    CREATE TABLE Documents (
      CountryCode  CHAR(2) REFERENCES Countries (CountryCode),
      DocumentID   INT UNSIGNED,
      DocumentName VARCHAR(255),
      -- etc.
      PRIMARY KEY (CountryCode, DocumentID)
    );
    
    CREATE TABLE CompanyDocuments (
      CompanyID   BIGINT UNSIGNED REFERENCES Companies (DocumentID),
      CountryCode CHAR(2)         REFERENCES Countries (CountryCode),
      DocumentID  INT    UNSIGNED,
      Expiry      DATE,
      PRIMARY KEY (CompanyID, DocumentID),
      FOREIGN KEY (CountryCode, DocumentID) REFERENCES
        Documents (CountryCode, DocumentID)
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大