LP#1904244: schema: make fund.code NOT NULL
authorGalen Charlton <gmc@equinoxOLI.org>
Fri, 16 Apr 2021 20:59:51 +0000 (16:59 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 12 Aug 2021 19:29:26 +0000 (15:29 -0400)
Any funds whose code was null will have it set to "FUND-WITH-ID-$id"

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/upgrade/ZZZZ.schema.make-acqf-code-not-null.sql [new file with mode: 0644]

index 87c0a50..0cfb608 100644 (file)
@@ -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 (file)
index 0000000..f923c11
--- /dev/null
@@ -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;