From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Enforce primary key on every table during dev?
Date: Wed, 28 Feb 2018 15:46:41 +0200
Message-ID: <c55322a0-7956-8825-aec0-68c38a0aa154@matrix.gatewaynet.com> (raw)
In-Reply-To: <CAMa1XUie6LD140KdMY7cst41uCaa5B1YEgJ3GH3XSgDh2WXguQ@mail.gmail.com>
References: <CAMa1XUie6LD140KdMY7cst41uCaa5B1YEgJ3GH3XSgDh2WXguQ@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: achill@matrix.gatewaynet.com
Subject: Re: Enforce primary key on every table during dev?
In-Reply-To: <c55322a0-7956-8825-aec0-68c38a0aa154@matrix.gatewaynet.com>
References: <CAMa1XUie6LD140KdMY7cst41uCaa5B1YEgJ3GH3XSgDh2WXguQ@mail.gmail.com> <c55322a0-7956-8825-aec0-68c38a0aa154@matrix.gatewaynet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox