Senior
How did you manage user access rights to the database? How did you create user groups and assign permissions?
sobes.tech AI
Answer from AI
To manage access rights to a database, I usually use built-in mechanisms of the DBMS, such as roles and user groups. I create groups (roles) with specific sets of privileges — for example, read, write, administration. Then I add users to these groups, which simplifies access management.
Example in PostgreSQL:
-- Create a role with read rights
CREATE ROLE readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
-- Create a user
CREATE USER user1 WITH PASSWORD 'password';
-- Add user to role
GRANT readonly TO user1;
This approach allows centralized management of rights by changing them in roles, rather than individually for each user. In large systems, I also apply the principle of least privilege to minimize risks.