2012-05-17 65 views
2

我目前正在創建一個應用程序,用戶可以從網站(將與他們安裝他們的服務器上的插件進行交互)控制的Minecraft服務器。我試圖想出一個合適的設計來允許每個服務器定義他們自己的用戶權限組。最後,會爲每個服務器選擇一個預定義的選項列表(我的插件將知道如何處理的選項),並將其分配給他們創建的組。我的目標有這麼本網站上的1個單用戶將有可能能夠在一臺服務器面板多個組,以及用戶能夠被分配給多臺服務器面板。架構爲用戶角色/權限

這是我目前已經想出了數據庫佈局:

Table: Roles  (will hold the predefined roles) 
    Columns: 
    serverTypeId (to distinguish between roles allowed for the 2 versions of minecraft) 
    roleId  (the role's unique id, primary key) 
    roleName  (some name to distinguish the role's purpose) 

Table: ServerGroup (will hold the custom per server groups) 
    Columns: 
    serverId   (the server's unique id) 
    groupId (the server role's unique id, primary key) 
    groupName (name given to group, like Staff, Admin, etc) 
    roleList   (a csv list of roleId's from the Roles table) 

Table: ServerPermissions 
    Columns: 
    serverId  (the server's unique id) 
    serverGroupId (the server's groupId that this user belongs to) 
    userId   (the user's id that is unique to the whole website) 

有沒有更好的方式來做到這一點?這是我能夠想出的最佳方式。我不是對SQL最熟悉的人,並且正在尋找改進方法。

回答

1

這看起來像一個相當雄厚的設計,有一點需要注意。 ServerGroup表中的roleList列是所謂的列中的重複組,應該避免。不要將所有角色id填充到單個列中,而應將其分解爲單獨的表,這將作爲角色和ServerGroup之間的聯結。

Table: ServerGroupRoles (will list roles for each ServerGroup) 
    Columns: 
    groupID (foreign key to ServerGroup) 
    roleID (foreign key to Roles) 
    Primary Key: groupID, roleID 

對於一個擁有的ServerGroup每個角色都會有ServerGroupRoles一個記錄。這種方法重複羣體的好處是易於搜索和維護。查詢,以檢查爲的ServerGroup一個特定角色的存在,那麼將有可能使用上的平等索引的查找,而不是使用像索引掃描。在維護方面,從ServerGroup中刪除一個角色是一個簡單的DELETE/WHERE語句,而不是不必要的昂貴的字符串操作。

如果你的Web應用程序要求的權限來爲CSV字符串處理,這將是微不足道的建設從對ServerGroupRoles查詢字符串。但是,如果應用程序發生變化,則不會因重複組造成的低效率而陷入困境。

+1

RoleList中列是我不能肯定的,並沒有真的喜歡,我簡直不知道如何來取代它。你解釋的方式更有意義。謝謝! –