From a7d3a3f31ef1e289231043fb51f129b641018348 Mon Sep 17 00:00:00 2001
From: "Karl O. Pinc" <kop@karlpinc.com>
Date: Fri, 2 Feb 2024 11:41:25 -0600
Subject: [PATCH] Add COMM_MEMBS_SOURCES table

Validates the StartSource and EndSource columns of COMM_MEMBS.
---
 db/schemas/codes/tables/Makefile              |  1 +
 .../codes/tables/create/comm_membs_sources.m4 | 27 +++++++++++
 .../sokwedb/tables/create/comm_membs.m4       |  8 +++-
 doc/src/code_tables.m4                        | 45 ++++++++++++++++++-
 doc/src/epilog.inc.m4                         |  7 +++
 doc/src/tables/comm_membs.m4                  | 12 +++--
 6 files changed, 93 insertions(+), 7 deletions(-)
 create mode 100644 db/schemas/codes/tables/create/comm_membs_sources.m4

diff --git a/db/schemas/codes/tables/Makefile b/db/schemas/codes/tables/Makefile
index cd6f7f1..6297988 100644
--- a/db/schemas/codes/tables/Makefile
+++ b/db/schemas/codes/tables/Makefile
@@ -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 := comm_ids \
+         comm_membs_sources \
          departtypes \
          entrytypes \
          people
diff --git a/db/schemas/codes/tables/create/comm_membs_sources.m4 b/db/schemas/codes/tables/create/comm_membs_sources.m4
new file mode 100644
index 0000000..89e5697
--- /dev/null
+++ b/db/schemas/codes/tables/create/comm_membs_sources.m4
@@ -0,0 +1,27 @@
+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
+
+support_table(`comm_membs_sources', `CommMembsSource', `TEXT', `
+           emptytext_check(`CommMembsSource')'
+)
diff --git a/db/schemas/sokwedb/tables/create/comm_membs.m4 b/db/schemas/sokwedb/tables/create/comm_membs.m4
index 82dff65..d5b2f36 100644
--- a/db/schemas/sokwedb/tables/create/comm_membs.m4
+++ b/db/schemas/sokwedb/tables/create/comm_membs.m4
@@ -32,9 +32,13 @@ CREATE TABLE comm_membs (
      CONSTRAINT "CommID must be a COMM_IDS.CommID value"
        REFERENCES comm_ids (commid)
   ,startsource TEXT NOT NULL
-     notonlyspaces_check(`StartSource')
+     CONSTRAINT
+       "StartSource must be a COMM_MEMBS_SOURCES.CommMembsSource value"
+       REFERENCES comm_membs_sources (commmembssource)
   ,endsource TEXT NOT NULL
-     notonlyspaces_check(`EndSource')
+     CONSTRAINT
+       "EndSource must be a COMM_MEMBS_SOURCES.CommMembsSource value"
+       REFERENCES comm_membs_sources (commmembssource)
   -- table constraints
   CONSTRAINT "StartDate must not be after EndDate"
     CHECK (startdate <= enddate)
diff --git a/doc/src/code_tables.m4 b/doc/src/code_tables.m4
index d827188..ffd720f 100644
--- a/doc/src/code_tables.m4
+++ b/doc/src/code_tables.m4
@@ -1,4 +1,4 @@
-.. Copyright (C) 2023  The Meme Factory, Inc.  www.karlpinc.com
+.. Copyright (C) 2023, 2024  The Meme Factory, Inc.  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
@@ -98,6 +98,49 @@ MembCriteria (Membership Criteria)
 |COMM_IDS.MembCriteria_summary| |notonlyspaces| |notnull|
 
 
+.. _COMM_MEMBS_SOURCES:
+
+COMM_MEMBS_SOURCES (COMMunity MEMBershipS SOURCES)
+--------------------------------------------------
+
+.. |COMM_MEMBS_SOURCES_summary| replace::
+   Contains one row for each data source from which community membership
+   information is derived.
+
+|COMM_MEMBS_SOURCES_summary|
+
+
+Special Values
+``````````````
+None.
+
+
+Column Descriptions
+```````````````````
+
+.. _COMM_MEMBS_SOURCES.CommMembsSource:
+
+CommMembsSource
+'''''''''''''''
+
+.. |COMM_MEMBS_SOURCES.CommMembsSource_summary| replace::
+   A somewhat abbreviated description which identifies a data source
+   from which community membership can be derived.
+
+|COMM_MEMBS_SOURCES.CommMembsSource_summary|  |keycol|
+
+
+.. _COMM_MEMBS_SOURCES.Description:
+
+Description
+'''''''''''
+
+.. |COMM_MEMBS_SOURCES.Description_summary| replace::
+   A longer description of the CommMembsSource identifier.
+
+|COMM_MEMBS_SOURCES.Description_summary| |emptytext|
+
+
 .. _DEPARTTYPES:
 
 DEPARTTYPES (community Departure reasons)
diff --git a/doc/src/epilog.inc.m4 b/doc/src/epilog.inc.m4
index 0faaa4a..f5ba089 100644
--- a/doc/src/epilog.inc.m4
+++ b/doc/src/epilog.inc.m4
@@ -133,6 +133,13 @@ sdb_generated_rst()dnl
 .. |COMM_MEMBS.StartSource| replace:: :ref:`CommID <COMM_MEMBS.StartSource>`
 .. |COMM_MEMBS.EndSource| replace:: :ref:`CommID <COMM_MEMBS.EndSource>`
 
+.. |COMM_MEMBS_SOURCES|
+   replace:: :ref:`COMM_MEMBS_SOURCES <COMM_MEMBS_SOURCES>`
+.. |COMM_MEMBS_SOURCES.CommMembsSource|
+   replace:: :ref:`CommMembsSource <COMM_MEMBS_SOURCES.CommMembsSource>`
+.. |COMM_MEMBS_SOURCES.Description|
+   replace:: :ref:`Description <COMM_MEMBS_SOURCES.Description>`
+
 .. |DEPARTTYPES| replace:: :ref:`DEPARTTYPES <DEPARTTYPES>`
 .. |DEPARTTYPES.DepartType|
    replace:: :ref:`DepartType <DEPARTTYPES.DepartType>`
diff --git a/doc/src/tables/comm_membs.m4 b/doc/src/tables/comm_membs.m4
index c9fc5bf..e75bf1d 100644
--- a/doc/src/tables/comm_membs.m4
+++ b/doc/src/tables/comm_membs.m4
@@ -126,9 +126,11 @@ StartSource
 ```````````
 
 .. |COMM_MEMBS.StartSource_summary| replace::
-   Description of how the |COMM_MEMBS.StartDate| was determined.
+   The |COMM_MEMBS_SOURCES|.\ |COMM_MEMBS_SOURCES.CommMembsSource|
+   value which identifies the data source used to determine the
+   |COMM_MEMBS.StartDate|.
 
-|COMM_MEMBS.StartSource_summary| |notonlyspaces| |notnull|
+|COMM_MEMBS.StartSource_summary| |notnull|
 
 
 .. _COMM_MEMBS.EndSource:
@@ -137,6 +139,8 @@ EndSource
 `````````
 
 .. |COMM_MEMBS.EndSource_summary| replace::
-   Description of how the |COMM_MEMBS.EndDate| was determined.
+   The |COMM_MEMBS_SOURCES|.\ |COMM_MEMBS_SOURCES.CommMembsSource|
+   value which identifies the data source used to determine the
+   |COMM_MEMBS.EndDate|.
 
-|COMM_MEMBS.EndSource_summary| |notonlyspaces| |notnull|
+|COMM_MEMBS.EndSource_summary| |notnull|
-- 
2.34.1