未知的動態數據,我的工作系統,用於需要在哪裏上:多租戶,每個租戶
- PHP + PostgreSQL的
- 多租戶系統,採用單一數據庫對所有租戶(tenantId)。
每個租戶的數據是未知的,所以他們應該可以靈活地添加任何他們想要的數據:
- 例如用於帳戶表,
承租人1> account_no上| date_created | DUE_DATE
租戶2> account_holder | start_date | end_date | customer_name | ...
唯一的解決辦法,我可以看到這種情況下,使用鍵 - 值對的數據庫結構: - 例如
accounts table
id | tenant_id | key | value
1 1 account_no 12345
accounts_data table
account_id | key | value
1 date_created 01-01-2014
1 due_date 30-02-2014
抽籤背上我看到從長遠來看,這種做法:
- Monster queries
- Inefficient with large data
- Lots of coding to handle data validation, since no data types are there and everything is saved as string
- Filtering can be lots of work
有了這樣說,我會很感激的建議,以及是否有其他的方法,我可以用它來實現這一目標。
感謝您的迅速回復。我知道我正在走向編碼,查詢和工作的野獸。如果我可以修復所有租戶的列,事情會更容易,但在這裏我的情況是,租戶應該可以靈活地上傳他們想要的任何數據,然後再處理這些數據。有關我如何將不同的數據集/租戶納入數據庫的想法? – aiiwa
順便說一句,猜你的鏈接「企業設計」沒有把我帶到預定的頁面。 – aiiwa
@nsk基於他們需要的動態'CREATE'和'ALTER'表,使用'hstore'或'json'來存儲他們的行,或者使用一個無模式的數據庫。 –