From: Galen Charlton Date: Thu, 23 Sep 2021 14:30:57 +0000 (-0400) Subject: LP#1921057: stamp schema update X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=38ec822f587058a624e02cce47c130fee70fbaee;p=evergreen%2Ftadl.git LP#1921057: stamp schema update Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 985e8153e2..61afa1e3f4 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -92,7 +92,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1295', :eg_version); -- berkick / cmorgan / gmcharlt +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1296', :eg_version); -- csharp / rfrasur / gmcharlt CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/1296.schema.reporter-demographic-expansion.sql b/Open-ILS/src/sql/Pg/upgrade/1296.schema.reporter-demographic-expansion.sql new file mode 100644 index 0000000000..6eb91e7226 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/1296.schema.reporter-demographic-expansion.sql @@ -0,0 +1,38 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('1296', :eg_version); + +CREATE OR REPLACE VIEW reporter.demographic AS +SELECT u.id, + u.dob, + CASE + WHEN u.dob IS NULL + THEN 'Adult' + WHEN AGE(u.dob) > '18 years'::INTERVAL + THEN 'Adult' + ELSE 'Juvenile' + END AS general_division, + CASE + WHEN u.dob IS NULL + THEN 'No Date of Birth Entered'::text + WHEN age(u.dob::timestamp with time zone) >= '0 years'::interval and age(u.dob::timestamp with time zone) < '6 years'::interval + THEN 'Child 0-5 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '6 years'::interval and age(u.dob::timestamp with time zone) < '13 years'::interval + THEN 'Child 6-12 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '13 years'::interval and age(u.dob::timestamp with time zone) < '18 years'::interval + THEN 'Teen 13-17 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '18 years'::interval and age(u.dob::timestamp with time zone) < '26 years'::interval + THEN 'Adult 18-25 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '26 years'::interval and age(u.dob::timestamp with time zone) < '50 years'::interval + THEN 'Adult 26-49 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '50 years'::interval and age(u.dob::timestamp with time zone) < '60 years'::interval + THEN 'Adult 50-59 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '60 years'::interval and age(u.dob::timestamp with time zone) < '70 years'::interval + THEN 'Adult 60-69 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '70 years'::interval + THEN 'Adult 70+'::text + ELSE NULL::text + END AS age_division + FROM actor.usr u; + +COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql deleted file mode 100644 index 6cc62fb3d0..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql +++ /dev/null @@ -1,38 +0,0 @@ -BEGIN; - --- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -CREATE OR REPLACE VIEW reporter.demographic AS -SELECT u.id, - u.dob, - CASE - WHEN u.dob IS NULL - THEN 'Adult' - WHEN AGE(u.dob) > '18 years'::INTERVAL - THEN 'Adult' - ELSE 'Juvenile' - END AS general_division, - CASE - WHEN u.dob IS NULL - THEN 'No Date of Birth Entered'::text - WHEN age(u.dob::timestamp with time zone) >= '0 years'::interval and age(u.dob::timestamp with time zone) < '6 years'::interval - THEN 'Child 0-5 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '6 years'::interval and age(u.dob::timestamp with time zone) < '13 years'::interval - THEN 'Child 6-12 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '13 years'::interval and age(u.dob::timestamp with time zone) < '18 years'::interval - THEN 'Teen 13-17 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '18 years'::interval and age(u.dob::timestamp with time zone) < '26 years'::interval - THEN 'Adult 18-25 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '26 years'::interval and age(u.dob::timestamp with time zone) < '50 years'::interval - THEN 'Adult 26-49 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '50 years'::interval and age(u.dob::timestamp with time zone) < '60 years'::interval - THEN 'Adult 50-59 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '60 years'::interval and age(u.dob::timestamp with time zone) < '70 years'::interval - THEN 'Adult 60-69 Years Old'::text - WHEN age(u.dob::timestamp with time zone) >= '70 years'::interval - THEN 'Adult 70+'::text - ELSE NULL::text - END AS age_division - FROM actor.usr u; - -COMMIT;