Re: partial "on-delete set null" constraint

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: rob stone <floriparob(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: partial "on-delete set null" constraint
Date: 2015-01-26 00:20:34
Message-ID: CA+6hpamd8Yh+71ezLAXCyYs24fNGZRPUwb=xm40wQNOg==+2bQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 1. I have a table with mailmessages, which has an FK to a table of hub users.
> 2. I'd like to retain the content of message repository (with it's domain key not cleared), when I drop a particular username from service .... to release that username to others.
> 3. I try to do that with FK "on-update/on-delete" actions, but to no avail:

Interesting discussion on database theory!

If you switched to surrogate keys for all your tables, you could
soft-delete accounts with a deleted_at column, and then have a unique
index on username+domain (or username+domain_id?) that is WHERE
deleted_at IS NULL. Does that work? Probably you want the same
approach for the maildomains table to enforce unique non-deleted
domains.

It seems like if you want to retain data for auditing, you don't
really want to delete *anything*, including the username. Surrogate
keys and a partial unique index would let you do that I believe.

Paul

--
_________________________________
Pulchritudo splendor veritatis.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Smith 2015-01-26 11:32:19 Pattern matching ints
Previous Message Alban Hertroys 2015-01-25 17:07:40 Re: partial "on-delete set null" constraint