简体   繁体   中英

How to auto update column value in Child Table based on Parent Table?

My web app architecture for user access separated in two ways:- Manager Table (column: privilege) Employee Table (column: privilege, permission)

Where Manager is a Super-Admin account which will be used to subscribe our service based on package type(eg: basic, silver, gold).

For Employee, this acc will be created by Manager and share the same privilege of Manager by default(the subscribed service package). However, the Manager will need to set a permission level for each function in order for the Employee to be able to access the function in the web app.

The idea is, if session by manager acc, no permission needed. if session by employee, permission needed.

Problem: When a new row in Child table created, the default value of column 'privilege' should follow the same as Parent. Also, in event of Parent downgrade the privilege, the Child column value should follow as well.

Is there a way to achieve this from database perspective? I'm using postgresql. I'm aware this definitely can be achieve from backend side but with quite a lot of logic need to do for each CRUD operation.

You could try using triggers or stored procedures and put the logic in the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM