From 681eb021551377d67b1bcd4b8661638bd590b3e3 Mon Sep 17 00:00:00 2001 From: Chad Redman Date: Wed, 19 Feb 2025 18:02:09 -0500 Subject: [PATCH] Add midpoint tables for provisioning purposes --- base/Dockerfile | 4 +- .../postgres/01-init_grouper_mp_tables.sql | 97 +++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 base/container_files/postgres/01-init_grouper_mp_tables.sql diff --git a/base/Dockerfile b/base/Dockerfile index eebf6d6..31af06d 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -63,7 +63,7 @@ RUN chown -R ldap:ldap /var/lib/ldap /etc/openldap/slapd.d \ # Init grouper databases and grouper, needs ldap and db to be up COPY container_files/usr-local-bin/* /usr/local/bin/ COPY container_files/grouper/conf /opt/grouper/grouperWebapp/WEB-INF/classes/ -COPY container_files/postgres/00-init_dbs_and_users.sql /tmp/base/postgres/00-init_dbs_and_users.sql +COPY container_files/postgres/*.sql /tmp/base/postgres/ RUN . /usr/local/bin/library.sh \ && . /usr/local/bin/librarySetupPipe.sh \ @@ -75,7 +75,7 @@ RUN . /usr/local/bin/library.sh \ && sudo chown postgres:postgres /var/run/postgresql \ && su -l postgres -c "pg_ctl -D /var/lib/pgsql/data -l /tmp/pg_logfile start" \ && while ! nc -z localhost 5432 > /dev/null; do echo waiting for postgres to start; sleep 3; done \ - && psql -U postgres -f /tmp/base/postgres/00-init_dbs_and_users.sql \ + && for file in /tmp/base/postgres/*.sql; do echo $file; psql -U postgres -f $file; done \ && cd /opt/grouper/grouperWebapp/WEB-INF \ && ./bin/gsh.sh -registry -check -runscript -noprompt \ && pkill -HUP slapd \ diff --git a/base/container_files/postgres/01-init_grouper_mp_tables.sql b/base/container_files/postgres/01-init_grouper_mp_tables.sql new file mode 100644 index 0000000..b570122 --- /dev/null +++ b/base/container_files/postgres/01-init_grouper_mp_tables.sql @@ -0,0 +1,97 @@ +/* https://spaces.at.internet2.edu/pages/viewpage.action?spaceKey=Grouper&title=Grouper+MidPoint+provisioner */ + +\c grouper grouper + +CREATE TABLE gr_mp_groups ( + group_name varchar(1024) NULL, -- Name of group mapped in some way + id_index int8 NOT NULL, -- This is the integer identifier for a group and foreign key to group attributes and memberships + display_name varchar(1024) NULL, -- Display name of group mapped in some way + description varchar(1024) NULL, -- Description of group mapped in some way + last_modified int8 NOT NULL, -- Millis since 1970, will be sequential and unique + deleted varchar(1) NOT NULL, -- T or F. Deleted rows will be removed after they have had time to be processed + CONSTRAINT gr_mp_groups_pkey PRIMARY KEY (id_index) +); +CREATE INDEX gr_mp_groups_ddx ON gr_mp_groups(display_name); +CREATE INDEX gr_mp_groups_gdx ON gr_mp_groups(group_name); +CREATE UNIQUE INDEX gr_mp_groups_idx ON gr_mp_groups(id_index); +CREATE UNIQUE INDEX gr_mp_groups_ldx ON gr_mp_groups(last_modified); +COMMENT ON TABLE gr_mp_groups IS 'This table holds groups'; + +COMMENT ON COLUMN gr_mp_groups.group_name IS 'Name of group mapped in some way'; +COMMENT ON COLUMN gr_mp_groups.id_index IS 'This is the integer identifier for a group and foreign key to group attributes and memberships'; +COMMENT ON COLUMN gr_mp_groups.display_name IS 'Display name of group mapped in some way'; +COMMENT ON COLUMN gr_mp_groups.description IS 'Description of group mapped in some way'; +COMMENT ON COLUMN gr_mp_groups.last_modified IS 'Millis since 1970, will be sequential and unique'; +COMMENT ON COLUMN gr_mp_groups.deleted IS 'T or F. Deleted rows will be removed after they have had time to be processed'; + +CREATE TABLE gr_mp_subjects ( + subject_id_index int8 NOT NULL, -- This is the integer identifier for a subject and foreign key to subject attributes and memberships + subject_id varchar(1024) NULL, -- Subject ID mapped in some way + last_modified int8 NOT NULL, -- Millis since 1970, will be sequential and unique + deleted varchar(1) NOT NULL, -- T or F. Deleted rows will be removed after they have had time to be processed + CONSTRAINT gr_mp_subjects_pkey PRIMARY KEY (subject_id_index) +); +CREATE UNIQUE INDEX gr_mp_subjects_idx ON gr_mp_subjects(subject_id_index); +CREATE UNIQUE INDEX gr_mp_subjects_ldx ON gr_mp_subjects(last_modified); +CREATE INDEX gr_mp_subjects_sdx ON gr_mp_subjects(subject_id); +COMMENT ON TABLE gr_mp_subjects IS 'This table holds subjects'; + +COMMENT ON COLUMN gr_mp_subjects.subject_id_index IS 'This is the integer identifier for a subject and foreign key to subject attributes and memberships'; +COMMENT ON COLUMN gr_mp_subjects.subject_id IS 'Subject ID mapped in some way'; +COMMENT ON COLUMN gr_mp_subjects.last_modified IS 'Millis since 1970, will be sequential and unique'; +COMMENT ON COLUMN gr_mp_subjects.deleted IS 'T or F. Deleted rows will be removed after they have had time to be processed'; + +CREATE TABLE gr_mp_group_attributes ( + group_id_index int8 NOT NULL, -- This is the integer identifier for a group and foreign key to groups and memberships + attribute_name varchar(1000) NOT NULL, -- Attribute name for attributes not in the main group table + attribute_value varchar(4000) NULL, -- Attribute value could be null + last_modified int8 NOT NULL, -- Millis since 1970, will be sequential and unique + deleted varchar(1) NOT NULL, -- T or F. Deleted rows will be removed after they have had time to be processed + CONSTRAINT gr_mp_group_attributes_fk FOREIGN KEY (group_id_index) REFERENCES gr_mp_groups(id_index) ON DELETE CASCADE + ); +CREATE UNIQUE INDEX gr_mp_group_attributes_idx ON gr_mp_group_attributes(group_id_index, attribute_name, attribute_value); +CREATE UNIQUE INDEX gr_mp_group_attributes_ldx ON gr_mp_group_attributes(last_modified); +COMMENT ON TABLE gr_mp_group_attributes IS 'This table holds group attributes which are one to one or one to many to the groups table'; + +COMMENT ON COLUMN gr_mp_group_attributes.group_id_index IS 'This is the integer identifier for a group and foreign key to groups and memberships'; +COMMENT ON COLUMN gr_mp_group_attributes.attribute_name IS 'Attribute name for attributes not in the main group table'; +COMMENT ON COLUMN gr_mp_group_attributes.attribute_value IS 'Attribute value could be null'; +COMMENT ON COLUMN gr_mp_group_attributes.last_modified IS 'Millis since 1970, will be sequential and unique'; +COMMENT ON COLUMN gr_mp_group_attributes.deleted IS 'T or F. Deleted rows will be removed after they have had time to be processed'; + +CREATE TABLE gr_mp_memberships ( + group_id_index int8 NOT NULL, -- This is the foreign key to groups + subject_id_index int8 NOT NULL, -- This is the foreign key to subjects + last_modified int8 NOT NULL, -- Millis since 1970, will be sequential and unique + deleted varchar(1) NOT NULL, -- T or F. Deleted rows will be removed after they have had time to be processed + CONSTRAINT gr_mp_memberships_gfk FOREIGN KEY (group_id_index) REFERENCES gr_mp_groups(id_index) ON DELETE CASCADE, + CONSTRAINT gr_mp_memberships_sfk FOREIGN KEY (subject_id_index) REFERENCES gr_mp_subjects(subject_id_index) ON DELETE CASCADE + ); +CREATE UNIQUE INDEX gr_mp_memberships_idx ON gr_mp_memberships(group_id_index, subject_id_index); +CREATE UNIQUE INDEX gr_mp_memberships_ldx ON gr_mp_memberships(last_modified); +CREATE INDEX gr_mp_memberships_by_subject_idx ON gr_mp_memberships(subject_id_index); +COMMENT ON TABLE gr_mp_memberships IS 'This table holds memberships. The primary key is group_id_index and subject_id_index'; + +COMMENT ON COLUMN gr_mp_memberships.group_id_index IS 'This is the foreign key to groups'; +COMMENT ON COLUMN gr_mp_memberships.subject_id_index IS 'This is the foreign key to subjects'; +COMMENT ON COLUMN gr_mp_memberships.last_modified IS 'Millis since 1970, will be sequential and unique'; +COMMENT ON COLUMN gr_mp_memberships.deleted IS 'T or F. Deleted rows will be removed after they have had time to be processed'; + +CREATE TABLE gr_mp_subject_attributes ( + subject_id_index int8 NOT NULL, -- This is the integer identifier and foreign key to subjects + attribute_name varchar(1000) NOT NULL, -- Attribute name for attributes not in the main subject table + attribute_value varchar(4000) NULL, -- Attribute value could be null + last_modified int8 NOT NULL, -- Millis since 1970, will be sequential and unique + deleted varchar(1) NOT NULL, -- T or F. Deleted rows will be removed after they have had time to be processed + CONSTRAINT gr_mp_subject_attributes_fk FOREIGN KEY (subject_id_index) REFERENCES gr_mp_subjects(subject_id_index) ON DELETE CASCADE + ); +CREATE UNIQUE INDEX gr_mp_subject_attributes_idx ON gr_mp_subject_attributes(subject_id_index, attribute_name, attribute_value); +CREATE UNIQUE INDEX gr_mp_subject_attributes_ldx ON gr_mp_subject_attributes(last_modified); +COMMENT ON TABLE gr_mp_subject_attributes IS 'This table holds subject attributes which are one to one or one to many to the subjects table'; + +COMMENT ON COLUMN gr_mp_subject_attributes.subject_id_index IS 'This is the integer identifier and foreign key to subjects'; +COMMENT ON COLUMN gr_mp_subject_attributes.attribute_name IS 'Attribute name for attributes not in the main subject table'; +COMMENT ON COLUMN gr_mp_subject_attributes.attribute_value IS 'Attribute value could be null'; +COMMENT ON COLUMN gr_mp_subject_attributes.last_modified IS 'Millis since 1970, will be sequential and unique'; +COMMENT ON COLUMN gr_mp_subject_attributes.deleted IS 'T or F. Deleted rows will be removed after they have had time to be processed'; +