From 66687819b788e130e3d5aa515f2a3e125360825d Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Fri, 5 Jun 2026 19:11:12 +0000 Subject: [PATCH] New table macro eid_primary_key() Give the user a useful unique index name so they know what to do when the violate the index's constraint. --- db/include/tablemacros.m4 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/db/include/tablemacros.m4 b/db/include/tablemacros.m4 index 8452b9e..c8ba809 100644 --- a/db/include/tablemacros.m4 +++ b/db/include/tablemacros.m4 @@ -133,6 +133,31 @@ define([not_animid_column], emptytext_check(`AnimID')]) changequote(`,')dnl See above. + +dnl Define a EID column as a PRIMARY KEY, but allow specification of the +dnl index name +dnl +dnl Syntax: eid_primary_key(table, indexname) +dnl +dnl table The name of the table on which the primary key is +dnl to be declared, in upper case. +dnl indexname The name to give to the UNIQUE index on EID. +dnl +changequote([,]) +define([eid_primary_key], +[-- Give the primary key index a useful name so the user has a clue +-- when they violate it. +CREATE UNIQUE INDEX + "$1 has, at most, a 1-to-1 relationship with EVENTS" + ON $1 + (eid); + +ALTER TABLE $1 + ADD PRIMARY KEY + USING INDEX + "$1 has, at most, a 1-to-1 relationship with EVENTS";]) +changequote(`,')dnl See above. + -- -- Constraints -- -- 2.34.1