LP 2009066: Set invoice_item_fund_debit_fkey Deferrable user/dyrcona/lp2009066-acq-invoice_item_fund_debit_fkey-deferred
authorJason Stephenson <jason@sigio.com>
Fri, 3 Mar 2023 20:53:17 +0000 (15:53 -0500)
committerJason Stephenson <jason@sigio.com>
Fri, 3 Mar 2023 20:57:32 +0000 (15:57 -0500)
Make the foreign key relationship between acq.invoice_item and
acq.fund_debit deferrable so that fund debits can be deleted in the
same transactions as the invoice items.  Otherwise, the fund debits
cannot be deleted if at all if referenced by an invoice item.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-invoice_item_fund_debit_fkey-deferrable.sql [new file with mode: 0644]
docs/RELEASE_NOTES_NEXT/miscellaneous.adoc

index 3195fee..508a761 100644 (file)
@@ -924,7 +924,7 @@ CREATE TABLE acq.invoice_item ( -- for invoice-only debits: taxes/fees/non-bib i
     id              SERIAL      PRIMARY KEY,
     invoice         INT         NOT NULL REFERENCES acq.invoice (id) ON UPDATE CASCADE ON DELETE CASCADE,
     purchase_order  INT         REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
-    fund_debit      INT         REFERENCES acq.fund_debit (id),
+    fund_debit      INT         REFERENCES acq.fund_debit (id) DEFERRABLE INITIALLY DEFERRED,
     inv_item_type   TEXT        NOT NULL REFERENCES acq.invoice_item_type (code),
     title           TEXT,
     author          TEXT,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-invoice_item_fund_debit_fkey-deferrable.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-invoice_item_fund_debit_fkey-deferrable.sql
new file mode 100644 (file)
index 0000000..cd39f0e
--- /dev/null
@@ -0,0 +1,7 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE acq.invoice_item ALTER CONSTRAINT invoice_item_fund_debit_fkey DEFERRABLE INITIALLY DEFERRED;
+
+COMMIT;
index d417d85..7ad8d21 100644 (file)
@@ -9,3 +9,4 @@
 * `autogen.sh` can now accept a `-c` switch to specify the location of `opensrf_core.xml`. This is useful for certain multi-tenant setups of Evergreen. (LP#2003707)
 * Better organization of acquisitions line item alert fields (LP#2002977)
 * Prevent templates from applying or changing magical status in angular holdings editor (LP#1999401)
+* Make the foreign key relationship between the acq.invoice_item and acq.fund_debit tables deferrable so that fund debits can be deleted when they reference invoice items that are deleted in the same transaction. (LP#2009066)