Casbin = way to authorization
A place for Casbin developers and users
现在注册
已注册用户请  登录
主题样式选择
默认主题样式 ✅
知乎主题样式 
Kingside
Casnode  ›  Casbin

Database Schema

  •  
  •  
    Kingside · 5年前 · 59 次点击 
    这是一个创建于 1926 天前的主题,其中的信息可能已经有所发展或是发生改变。

    I just wonder what is the best practice to create a good database design. It doesnt matter what kind of Database. I mean how to structure the policy and models

    59 次点击  ∙  0 人收藏  
      Tweet Weibo 忽略主题 
    5 条回复   2021-01-24 10:56:37 +08:00
    hsluoyz
    hsluoyz5年前

    You don't need to design the DB table for Casbin policy, model is usually a string or text, which is usually not saved in DB. See:

    Kingside
    Kingside5年前

    When the string is not stored in the database than in a static file? But why? The whole application data is stored in the database. When permission changes you need to store the data in standard format. The Users and Roles are also stored in the Database. So why not save the relations to the permissions also in the database? I can not pass the Casbin Config as it is to the Client.

    hsluoyz
    hsluoyz5年前

    @Kingside Casbin model is only one single string. If you like you can manually write some code to store it into a DB table, only 1 row and only 1 column.

    Kingside
    Kingside5年前

    @hsluoyz I understood you well. You can store it in a single Database field. The downside of it, the format as it is is useless. An userfriendly application has something where you have a permission process like this: 1. Create Users in e.g Table: User 2. Create Role in e.g. Table Role 4. Create Rights in e.g. Table Right 5. Assign Rights to Roles in e.g. Table Role_Right 6. Assign Users to Roles in e.g. Table Role_User So when you have a database design like this you have to transform the data for Casbin. Wouldnt it be easier if Casbin would a similar database design schema? In youre application you have a control or form or something for each of these objects.

    hsluoyz
    hsluoyz5年前

    @Kingside

    1. Create Users in e.g Table User

    see: https://casbin.org/docs/en/overview#what-is-casbin Casbin doesn't maintain user list table because it's too customized.

    1. Create Role in e.g. Table Role

    Call API: GetAllRoles() https://casbin.org/docs/en/management-api#getallroles

    1. Create Rights in e.g. Table Right

    Call a lot of APIs like: https://casbin.org/docs/en/management-api#getpolicy

    1. Assign Rights to Roles in e.g. Table Role_Right

    Call a lot of APIs like: https://casbin.org/docs/en/management-api#getpolicy

    1. Assign Users to Roles in e.g. Table Role_User

    Call: https://casbin.org/docs/en/management-api#getgroupingpolicy

    Casbin doesn't use the "classic" 5 table model.

    关于   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   51 人在线   最高记录 52   ·     选择语言  ·     选择编辑器
    创意工作者们的社区
    World is powered by code
    VERSION: c3b0ae8 · 3ms · UTC 14:09 · PVG 22:09 · LAX 07:09 · JFK 10:09
    ♥ Do have faith in what you're doing.