Storing application permissions in a database

后端 未结 5 1591
一生所求
一生所求 2021-01-30 18:38

I\'m developing an application for our company that eventually will have lots of ways of restricting users to particular sections/modules. While the application is still small,

5条回答
  •  佛祖请我去吃肉
    2021-01-30 19:28

    In a very famous MySQL performance book High Performance MySQL, the author specifically mentioned ACL as where data type like SET could be used. They use following example to demonstrate such use cases:

    CREATE TABLE acl (
        permissions SET('CAN_READ', 'CAN_WRITE', 'CAN_DELETE') NOT NULL
    );
    
    INSERT INTO acl VALUES ('CAN_READ,CAN_WRITE');
    SELECT permissions FROM acl WHERE find_in_set('CAN_READ', permissions);
    

    The problem is that, mentioned in the book as well, you can't modify the permissions set easily (you have to use ALTER TABLE), neither can you declare a column typed SET as an index, which may causes performance issue.

    You can also use something like TINYINT to "wrap" the ACL list, the cons is that it's harder to read as well as to code SELECT sentence.

提交回复
热议问题