What is the best way to manage permissions for a web application - bitmask or database table?

前端 未结 9 768
感动是毒
感动是毒 2020-12-22 19:06

I\'m considering the best way to design a permissions system for an \"admin\" web application. The application is likely to have many users, each of whom could be assigned a

9条回答
  •  温柔的废话
    2020-12-22 19:23

    Permissions are usually key words with a 1, 0 or null (indicating inherit). With an bit system, you probably cannot create indexes on the user id and permission keyword; instead, you would have to scan every record to get the permission value.

    I would say go for the first option. It seems to me the better solution:

    create table permissions (
        user_id INT NOT Null,
        permission VARCHAR(255) NOT NULL,
        value TINYINT(1) NULL
    )
    alter table `permissions` ADD PRIMARY KEY ( `user_id` , `permission` ) 
    

提交回复
热议问题