From a428988bf68d2cfdeb8e5a65ab3794f3d6174ea0 Mon Sep 17 00:00:00 2001
From: "Karl O. Pinc kop@karlpinc.com" <kop@karlpinc.com>
Date: Sat, 20 Jan 2024 17:58:52 +0000
Subject: [PATCH] Create BIOGRAPHY_LOG and update docs with actual constraints

---
 db/schemas/sokwedb/tables/Makefile            |  3 +-
 .../sokwedb/tables/create/biography_log.m4    | 44 +++++++++++++++++++
 doc/src/tables/biography_log.m4               | 11 ++---
 3 files changed, 52 insertions(+), 6 deletions(-)
 create mode 100644 db/schemas/sokwedb/tables/create/biography_log.m4

diff --git a/db/schemas/sokwedb/tables/Makefile b/db/schemas/sokwedb/tables/Makefile
index 3591f66..05faf54 100644
--- a/db/schemas/sokwedb/tables/Makefile
+++ b/db/schemas/sokwedb/tables/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 2023 The Meme Factory, Inc.   http://www.karlpinc.com/
+# Copyright (C) 2023, 2024 The Meme Factory, Inc.   http://www.karlpinc.com/
 #
 #   This program is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU Affero General Public License as published by
@@ -21,6 +21,7 @@
 # This is important because the tables containing foreign keys must be put
 # into the database after the tables they reference.
 ORDER := biography \
+         biography_log \
          comm_membs \
          comm_memb_log \
          sightings
diff --git a/db/schemas/sokwedb/tables/create/biography_log.m4 b/db/schemas/sokwedb/tables/create/biography_log.m4
new file mode 100644
index 0000000..0bb3b5a
--- /dev/null
+++ b/db/schemas/sokwedb/tables/create/biography_log.m4
@@ -0,0 +1,44 @@
+dnl Copyright (C) 2024 The Meme Factory, Inc., http://www.karlpinc.com/
+dnl
+dnl   This program is free software: you can redistribute it and/or modify
+dnl   it under the terms of the GNU Affero General Public License as published
+dnl   by the Free Software Foundation, either version 3 of the License, or
+dnl   (at your option) any later version.
+dnl
+dnl   This program is distributed in the hope that it will be useful,
+dnl   but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl   GNU Affero General Public License for more details.
+dnl
+dnl   You should have received a copy of the GNU Affero General Public License
+dnl   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+dnl
+dnl Karl O. Pinc <kop@karlpinc.com>
+dnl
+dnl
+dnl m4 includes
+include(`copyright.m4')dnl
+include(`constants.m4')dnl
+include(`tablemacros.m4')dnl
+include(`grants.m4')dnl
+dnl
+
+CREATE TABLE biography_log (
+   blid INT GENERATED ALWAYS AS IDENTITY
+  ,dateofupdate DATE NOT NULL
+    CONSTRAINT "DateOfUpdate may not be before sdb_first_biography_log_date"
+      CHECK ('sdb_first_biography_log_date'::DATE <= dateofupdate)
+    CONSTRAINT "DateOfUpdate may not be after today's date"
+      CHECK (dateofupdate <= CURRENT_DATE)
+  ,animid_column(`animid', `AnimID', `NOT NULL')
+  ,description TEXT NOT NULL
+    emptytext_check(`Description')
+  ,rationale TEXT NOT NULL
+    emptytext_check(`Rationale')
+  ,madeby TEXT NOT NULL
+    CONSTRAINT "MadeBy must be a PEOPLE.Person value"
+      REFERENCES people (person)
+);
+
+grant_priv(`BIOGRAPHY_LOG')
+grant_seq_priv(`BIOGRAPHY_LOG', `BLID')
diff --git a/doc/src/tables/biography_log.m4 b/doc/src/tables/biography_log.m4
index 0f231da..a42f244 100644
--- a/doc/src/tables/biography_log.m4
+++ b/doc/src/tables/biography_log.m4
@@ -50,8 +50,9 @@ DateOfUpdate
 .. |BIOGRAPHY_LOG.DateOfUpdate_summary| replace::
    The date on which the update was made.
 
-|BIOGRAPHY_LOG.DateOfUpdate_summary| This date must not be before
-``sdb_first_biography_log_date``.
+|BIOGRAPHY_LOG.DateOfUpdate_summary| This date cannot be before
+``sdb_first_biography_log_date`` and cannot be after the current
+date.
 
 
 .. _BIOGRAPHY_LOG.AnimID:
@@ -60,8 +61,8 @@ AnimID (Animal IDentifier)
 ``````````````````````````
 
 .. |BIOGRAPHY.AnimID_summary| replace::
-   The short sequence of characters which uniquely identify the chimpanzee
-   who's demographic information was updated.
+   The |BIOGRAPHY|.\ |BIOGRAPHY.AnimID| which identifies the
+   chimpanzee who's demographic information was updated.
 
 |BIOGRAPHY.AnimID_summary| |keycol| |cannot_change|
 
@@ -85,7 +86,7 @@ Rationale
 .. |BIOGRAPHY_LOG.Rationale_summary| replace::
    A description of why the change was made.
 
-|BIOGRAPHY_LOG.Rationale_summary| |notonlyspaces| |notnull|
+|BIOGRAPHY_LOG.Rationale_summary| |notempty| |notnull|
 
 
 .. _BIOGRAPHY_LOG.MadeBy:
-- 
2.34.1