Re: Enforce primary key on every table during dev?

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Enforce primary key on every table during dev?
Date: 2018-02-28 13:46:41
Message-ID: c55322a0-7956-8825-aec0-68c38a0aa154@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 28/02/2018 15:34, Jeremy Finzel wrote:
> We want to enforce a policy, partly just to protect those who might forget, for every table in a particular schema to have a primary key.  This can't be done with event triggers as far as I can see,
> because it is quite legitimate to do:
>
> BEGIN;
> CREATE TABLE foo (id int);
> ALTER TABLE foo ADD PRIMARY KEY (id);
> COMMIT;
>
> It would be nice to have some kind of "deferrable event trigger" or some way to enforce that no transaction commits which added a table without a primary key.
>
> Any ideas?
cron job to check for tables without PK ? Although for a short period the offending table would be there live without a PK.
But IMO every table, in addition to PK, should have also natural unique keys as much as possible.
Better safe than sorry.
>
> Thanks,
> Jeremy

--
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John McKown 2018-02-28 13:52:57 Re: Enforce primary key on every table during dev?
Previous Message Jeremy Finzel 2018-02-28 13:34:17 Enforce primary key on every table during dev?