簡體   English   中英

用戶角色/權限的架構

[英]Schema for user roles/permissions

我目前正在創建一個應用程序,用戶可以在該應用程序中從網站控制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,正在尋找改進的方法。

這看起來像一個相當堅固的設計,但有一個警告。 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特定角色的查詢很可能是使用相等性對索引進行搜索,而不是使用LIKE對索引進行掃描。 在維護方面,從ServerGroup中刪除角色只是一個簡單的DELETE / WHERE語句,而不是不必要的昂貴字符串操作。

如果您的Web應用程序要求將權限作為CSV字符串處理,那么從針對ServerGroupRoles的查詢中構建字符串將是微不足道的。 但是,如果應用程序發生更改,則不會因重復組而導致效率低下。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM