From 4c3a96cf96a0d638035092d248e2f50eef6eaf4b Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 16 Apr 2021 16:59:51 -0400 Subject: [PATCH] LP#1904244: schema: make fund.code NOT NULL Any funds whose code was null will have it set to "FUND-WITH-ID-$id" Signed-off-by: Galen Charlton Signed-off-by: Ruth Frasur Signed-off-by: Bill Erickson --- Open-ILS/src/sql/Pg/200.schema.acq.sql | 2 +- .../sql/Pg/upgrade/ZZZZ.schema.make-acqf-code-not-null.sql | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/ZZZZ.schema.make-acqf-code-not-null.sql diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql index 87c0a50d42..0cfb6089dc 100644 --- a/Open-ILS/src/sql/Pg/200.schema.acq.sql +++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql @@ -214,7 +214,7 @@ CREATE TABLE acq.fund ( name TEXT NOT NULL, year INT NOT NULL DEFAULT EXTRACT( YEAR FROM NOW() ), currency_type TEXT NOT NULL REFERENCES acq.currency_type (code) DEFERRABLE INITIALLY DEFERRED, - code TEXT, + code TEXT NOT NULL, rollover BOOL NOT NULL DEFAULT FALSE, propagate BOOL NOT NULL DEFAULT TRUE, active BOOL NOT NULL DEFAULT TRUE, diff --git a/Open-ILS/src/sql/Pg/upgrade/ZZZZ.schema.make-acqf-code-not-null.sql b/Open-ILS/src/sql/Pg/upgrade/ZZZZ.schema.make-acqf-code-not-null.sql new file mode 100644 index 0000000000..f923c1131e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/ZZZZ.schema.make-acqf-code-not-null.sql @@ -0,0 +1,11 @@ +BEGIN; + +-- if there are any straggling funds without a code set, fix that +UPDATE acq.fund +SET code = 'FUND-WITH-ID-' || id +WHERE code IS NULL; + +ALTER TABLE acq.fund + ALTER COLUMN code SET NOT NULL; + +COMMIT; -- 2.11.0