Frage

I was wondering how to take the best way to solve this situation. It's a database structure problem... Let's see the case.

I have some databases which have the same structure (let's say db_A, db_B, db_C). They are identical in structure but with different data, of course.

There's another database with permissions (db_permissions), and another with users (db_users).

The db_permissions structure table would be ID, permission; where permission is a unique string identifier (like post:create).

Now, there's a user which has different permissions on each table. For example: user 123 would have rights to write a post in db_A, rights to only read posts on db_B, and rights to read, write and delete posts on db_C.

My question is, how should I reference the permissions on each table?

  • Do I reference the unique string identifier (like post:create, post:read) and add this directly to each database permissions (like user_id - permission_string)?

  • Or do I reference them by the ID primary key on the permissions database (like user_id - permission_id)?

In my PHP script, when I check the permissions, I check by the unique string identifier.

What would you recommend? Would you use another structure for the permissions?

Thanks for your time and answers!

War es hilfreich?

Lösung

If you have a permissions table that maps IDs to permission strings, then you should use those IDs in other tables that store user permissions.

You should have a table_permissions table, with 3 columns: user_ID, table_ID, permission_ID.

Andere Tipps

Indexes / references should always be type integer if you want to keep performance

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top