summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-11-30 20:18:00 +0900
committerChristian Grothoff <grothoff@gnunet.org>2023-11-30 20:18:00 +0900
commit6cbab99697f9fd06fe4ed97edaf07414dad4f0db (patch)
treef70f9d3eee462933a7c64001cb793036342fdb24 /src/exchangedb
parent6dc78a22b39a9a84bb7a3d46dccc3f7110e42a4b (diff)
downloadexchange-6cbab99697f9fd06fe4ed97edaf07414dad4f0db.tar.gz
exchange-6cbab99697f9fd06fe4ed97edaf07414dad4f0db.tar.bz2
exchange-6cbab99697f9fd06fe4ed97edaf07414dad4f0db.zip
keep foreign constraint properly in
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/0002-batch_deposits.sql28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/exchangedb/0002-batch_deposits.sql b/src/exchangedb/0002-batch_deposits.sql
index 57a476a97..71a4b4205 100644
--- a/src/exchangedb/0002-batch_deposits.sql
+++ b/src/exchangedb/0002-batch_deposits.sql
@@ -111,13 +111,6 @@ BEGIN
' PRIMARY KEY (batch_deposit_serial_id) '
',ADD CONSTRAINT ' || table_name || '_merchant_pub_h_contract_terms'
' UNIQUE (shard, merchant_pub, h_contract_terms)'
- -- The policy_details_serial_id is a foreign key.
- -- But, due to partitioning its table by a different column, we can not
- -- simply reference policy_details_serial_id of the policy_details. Thus,
- -- the following is commented out:
- -- ',ADD CONSTRAINT ' || table_name || '_foreign_policy_details'
- -- ' FOREIGN KEY (policy_details_serial_id) '
- -- ' REFERENCES policy_details (policy_details_serial_id) ON DELETE RESTRICT'
);
EXECUTE FORMAT (
'CREATE INDEX ' || table_name || '_by_ready '
@@ -137,6 +130,22 @@ BEGIN
END
$$;
+CREATE OR REPLACE FUNCTION foreign_table_batch_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'batch_deposits';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_policy_details'
+ ' FOREIGN KEY (policy_details_serial_id) '
+ ' REFERENCES policy_details (policy_details_serial_id) ON DELETE RESTRICT'
+ );
+END
+$$;
+
INSERT INTO exchange_tables
(name
@@ -154,5 +163,10 @@ INSERT INTO exchange_tables
,'exchange-0002'
,'constrain'
,TRUE
+ ,FALSE),
+ ('batch_deposits'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
,FALSE)
;