Proposal: ON UPDATE REMOVE foreign key action

From: Kirill Berezin <enelar(at)exsul(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Proposal: ON UPDATE REMOVE foreign key action
Date: 2016-10-03 15:37:29
Message-ID: CAAObgf-A5=5NOjwvHsOS0SuWb+QLg2O=oF6oa3RfZ8QANd9ArQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

*One-line Summary:* On foreign key update we unable to remove all depended
records. Currently we have "ON REMOVE CASCADE DELETE", but no "ON UPDATE
CASCADE DELETE". We can only update field to NULL or DEFAULT.

*Business Use-case:* Cache expiration on hash/version update. Revoke all
access on account id update.

In my case i met this situation: I am using access links to share user
account. Account owner can give private link to somebody, and its session
become mirrored. (Owner access to account granted). You cant imagine
facebook desktop and mobile sessions. It's just shortcut for
entering credentials. Now i am implementing "revoke all but me". Its done
simple, since each user is uuid indexed, i am just generate new uuid for
current account. Old uuid become invalid to other sessions - since no
record is found in base.
I want to remove any pending access links, prevent bad guy restore access.
I can possibly set linked account to NULL, and then clear record on
expiration, but i feel that automatically removing on update event is more
rational.

*User impact with the change:* Instead of writing "on update" triggers for
each depended table, wished action is done by single line.

*Implementation details:* On cascade switch "update" action to "delete".

*Estimated Development Time:* Few hours or less.

*Opportunity Window Period:* Non applicable, minor feature

*Budget Money:* I am ready to implement myself, if approved.

*Contact Information:* enelar(at)exsul(dot)net

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-10-03 16:29:18 Removing link-time cross-module refs in contrib
Previous Message Stephen Frost 2016-10-03 15:16:34 Re: pgbench more operators & functions