From cf2e37cd876651e799893e8fe5babb51a9e12dd7 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Sun, 27 Nov 2022 21:21:04 +0100
Subject: more work on SQL refactoring

---
 src/exchangedb/0002-deposits.sql | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'src/exchangedb/0002-deposits.sql')

diff --git a/src/exchangedb/0002-deposits.sql b/src/exchangedb/0002-deposits.sql
index 2be51903..679103c4 100644
--- a/src/exchangedb/0002-deposits.sql
+++ b/src/exchangedb/0002-deposits.sql
@@ -26,7 +26,7 @@ BEGIN
   PERFORM create_partitioned_table(
     'CREATE TABLE %I'
       '(deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
-      ',partition INT8 NOT NULL'
+      ',shard INT8 NOT NULL'
       ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
       ',known_coin_id INT8 NOT NULL' -- FIXME: column needed!?
       ',amount_with_fee_val INT8 NOT NULL'
@@ -130,10 +130,13 @@ BEGIN
   EXECUTE FORMAT (
     'ALTER TABLE ' || table_name ||
     ' ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+    ' FOREIGN KEY (coin_pub) '
     ' REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
     ',ADD CONSTRAINT ' || table_name || '_foreign_coin_id'
+    ' FOREIGN KEY (known_coin_id) '
     ' REFERENCES known_coins (known_coin_id) ON DELETE CASCADE'
     ',ADD CONSTRAINT ' || table_name || '_foreign_policy_details'
+    ' FOREIGN KEY (policy_details_serial_id) '
     ' REFERENCES policy_details (policy_details_serial_id) ON DELETE CASCADE'
   );
 END
@@ -152,7 +155,7 @@ BEGIN
   PERFORM create_partitioned_table(
   'CREATE TABLE %I'
     '(wire_deadline INT8 NOT NULL'
-    ',partition INT8 NOT NULL'
+    ',shard INT8 NOT NULL'
     ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
     ',deposit_serial_id INT8'
     ') %s ;'
@@ -182,7 +185,7 @@ BEGIN
   EXECUTE FORMAT (
     'CREATE INDEX ' || table_name || '_main_index '
     'ON ' || table_name || ' '
-    '(wire_deadline ASC, partition ASC, coin_pub);'
+    '(wire_deadline ASC, shard ASC, coin_pub);'
   );
 END
 $$;
-- 
cgit v1.2.3

