LP#1893463: Protect against null emails
authorMike Rylander <mrylander@gmail.com>
Mon, 12 Oct 2020 19:51:29 +0000 (15:51 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Thu, 22 Oct 2020 19:51:40 +0000 (15:51 -0400)
Unique indexes on nullable columns will allow multiple conceptually
unique rows if the nullable columns are, in fact, NULL because NULL does
not equal itself.  This commit uses COALESCE to make sure that the
nullable email column in the reporter.schedule table gets a value of the
empty string for the purposes of the unique index.  The upgrade script
now also takes this into account and ignores the email column.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>

Open-ILS/src/sql/Pg/reporter-schema.sql
Open-ILS/src/sql/Pg/upgrade/1241.schema.reporter_schedule_uniqueness.sql

index eb07999..68b7cfc 100644 (file)
@@ -110,7 +110,7 @@ CREATE TABLE reporter.schedule (
 );
 CREATE INDEX rpt_sched_runner_idx ON reporter.schedule (runner);
 CREATE INDEX rpt_sched_folder_idx ON reporter.schedule (folder);
-CREATE UNIQUE INDEX rpt_sched_recurrence_once_idx ON reporter.schedule (report,folder,runner,run_time,email);
+CREATE UNIQUE INDEX rpt_sched_recurrence_once_idx ON reporter.schedule (report,folder,runner,run_time,COALESCE(email,''));
 
 CREATE OR REPLACE VIEW reporter.simple_record AS
 SELECT r.id,
index 934aa76..6716658 100644 (file)
@@ -8,7 +8,7 @@ SET CONSTRAINTS ALL IMMEDIATE; -- to address "pending trigger events" error
 CREATE TABLE reporter.schedule_original (LIKE reporter.schedule);
 INSERT INTO reporter.schedule_original SELECT * FROM reporter.schedule;
 TRUNCATE reporter.schedule;
-INSERT INTO reporter.schedule (SELECT DISTINCT ON (report, folder, runner, run_time, email) id, report, folder, runner, run_time, start_time, complete_time, email, excel_format, html_format, csv_format, chart_pie, chart_bar, chart_line, error_code, error_text FROM reporter.schedule_original);
+INSERT INTO reporter.schedule (SELECT DISTINCT ON (report, folder, runner, run_time) id, report, folder, runner, run_time, start_time, complete_time, email, excel_format, html_format, csv_format, chart_pie, chart_bar, chart_line, error_code, error_text FROM reporter.schedule_original);
 \qecho NOTE: This has created a backup of the original reporter.schedule
 \qecho table, named reporter.schedule_original.  Once you are sure that everything
 \qecho works as expected, you can delete that table by issuing the following:
@@ -17,7 +17,7 @@ INSERT INTO reporter.schedule (SELECT DISTINCT ON (report, folder, runner, run_t
 \qecho
 
 -- Explicitly supply the name because it is referenced in clark-kent.pl
-CREATE UNIQUE INDEX rpt_sched_recurrence_once_idx ON reporter.schedule (report,folder,runner,run_time,email);
+CREATE UNIQUE INDEX rpt_sched_recurrence_once_idx ON reporter.schedule (report,folder,runner,run_time,COALESCE(email,''));
 
 COMMIT;