問題描述
我們有一個包含子域的站點,例如:
We have a site which has sub domains like:
- example.com - 主站點
- food.example.com
- fashion.example.com
并且每個域和子域都有不同的數據庫,如下所示:
And each domain and sub domain has a different database, like this:
- exampleDB - 帶有用戶表的主數據庫
- foodDB
- 時尚數據庫
你嘗試過什么?
現在,對于單點登錄,我們計劃重定向主站點中的用戶進行注冊.
Right now, for single sign in we have planned to redirect users in our Main Site for signing up.
子域中的訂單處理從主數據庫中獲取 UserID 并存儲在相應子域的 Orders 表中.
While order processing in sub domains get the UserID from main DB and store in respective sub domain's Orders table.
出于報告目的,我們將沒有 FK 約束
的 UserID
存儲在 Orders
表中,因為我們有單獨的數據庫.
For reporting purposes we store the UserID
without FK constraint
in the Orders
table since we have separate database.
我可以在這里看到 堆棧交換站點有單獨的數據庫,但它有單獨的 用戶 表也是嗎?
I can see here that stack exchange sites have separate databases, but does it have separate users tables too?
StackExchange Network 配置文件是否存儲在單獨的數據庫中?
我可以從這里看到 每個站點的用戶表都有 StackExchange Network 配置文件的 AccountId.
I can see from here that Every site's user table has AccountId of StackExchange Network profile.
示例:
這里是 ID:7598 的 Nick Craver 網絡配置文件
Here is Nick Craver Network Profile with ID:7598
他在歷史站點中的個人資料的帳戶 ID 與相同 ID 關聯:7598 檢查 this 查詢.
His profile in History Site has Account ID Linked with same ID:7598 check this query.
我在數據啞巴中的任何地方都看不到Accounts
表,那么 AccountId
被存儲了嗎?以及如何使用 AccountId
在多個站點中完成 SSO?
I can't see the Accounts
table anywhere in data dumbs , So Were is AccountId
stored? And how is SSO done in multiple sites using AccountId
?
我的問題:我們是否需要主數據庫中的單個用戶表,或者我們必須為子域的數據庫和Link Main DB UserID
創建單獨的用戶表,但不需要FK 約束?哪個是購物網站的最佳設計?
My Question: Do we need a single user table in Main DB or we have to create separate user tables for the sub domain's database and Link Main DB UserID
but not FK constraint? Which is the best design for a shopping site?
任何幫助都會很棒.
推薦答案
您提到的 UserID 僅在單個 DB 的特定 Users 表中相同.它實際上不是您域中任何用戶的標識符.要識別多個數據庫中的用戶,您需要為每個用戶提供域級 ID.一種簡單的方法是將一個名為 UID 或類似名稱的屬性(列)添加到全局唯一 ID(GUID,請參閱 https://msdn.microsoft.com/en-us/library/system.guid(v=vs.110).aspx) 并將其用作域級 ID 來識別用戶而不是 UserId.通過這種方式,您可以自由地將用戶信息存儲在域中的多個數據庫中.所以:
The UserID you mentioned is only identical in a specific Users table in a single DB. It's actually not an identifier of any user in your domain. To identify users across multiple databases, you will need a domain-level ID for every user. A simple way is to add one more property (column) named UID or something like that to User class (table), of Global Unique Id (GUID, see https://msdn.microsoft.com/en-us/library/system.guid(v=vs.110).aspx) and use it as domain-level ID to identify users instead of UserId. This way you can freely store user information in multiple databases in your domain. So:
- 您只能在每個子域的數據庫中保存域級 ID,并使用該 ID 從主域數據庫中查詢完整的用戶配置文件.優點:消耗更少的內存.權衡:在分布式系統中,從子域查詢用戶信息需要更長的時間,因為信息駐留在主數據庫中.
- 您可以在所有數據庫中保存完整的用戶信息,包括主數據庫和子數據庫.優點:更快的查詢.缺點:消耗更多內存,當用戶信息發生變化時,您必須在所有數據庫之間同步.
這篇關于設計用于單點登錄的用戶表以跨子域使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!