django-postgresql-setrole
module sets SET ROLE
statement in every connection to Postgres.
This module is a good solution in case you have more than one user(role) in your database and they all do read/write operations in the same database. In postgres role
inheritance is one directional and Postgres
will not let you set up circular membership loops. Learn more about role inheritance constraints in Postgres
here
So not have conflict it is a good practice to have one role lets say ROLE_A
and the rest inherit the rights of ROLE_A
and in case there is a need to create new object in db it should be done as ROLE_A
. In postgres it can be done using SET ROLE
command unless we don't want to have a database and a lot of ownerships in it (different tables with different owners etc.).
Python 2.7.*
- Add
postgresql_setrole
toINSTALLED_APPS
- Add
SET_ROLE
in your database connection. E.g.
"default": {
..., # other settings
"SET_ROLE": "owner",
}.
}
This project is licensed under the MIT License - see the LICENSE.md file for details
Feel free to contact us and share your experience.