aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/0002-wire_targets.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-11-27 02:00:38 +0100
committerChristian Grothoff <christian@grothoff.org>2022-11-27 02:00:38 +0100
commitbe2c11a1797d8d16b86439a80a4f110f82bb5829 (patch)
treef0a950be0f80ced5ab68b6f65d11edb5dc09a3b5 /src/exchangedb/0002-wire_targets.sql
parent9580dd19c23e5591cc022dce717eca7bc745c5b0 (diff)
downloadexchange-be2c11a1797d8d16b86439a80a4f110f82bb5829.tar.xz
more sql refactoring
Diffstat (limited to 'src/exchangedb/0002-wire_targets.sql')
-rw-r--r--src/exchangedb/0002-wire_targets.sql30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/exchangedb/0002-wire_targets.sql b/src/exchangedb/0002-wire_targets.sql
index 5e8f19059..08bc468d3 100644
--- a/src/exchangedb/0002-wire_targets.sql
+++ b/src/exchangedb/0002-wire_targets.sql
@@ -23,7 +23,7 @@ AS $$
BEGIN
PERFORM create_partitioned_table(
'CREATE TABLE IF NOT EXISTS %I'
- '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
+ '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
',wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32)'
',payto_uri VARCHAR NOT NULL'
') %s ;'
@@ -31,19 +31,34 @@ BEGIN
,'PARTITION BY HASH (wire_target_h_payto)'
,shard_suffix
);
+ PERFORM comment_partitioned_table(
+ 'All senders and recipients of money via the exchange'
+ ,'wire_targets'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)'
+ ,'payto_uri'
+ ,'wire_targets'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Unsalted hash of payto_uri'
+ ,'wire_target_h_payto'
+ ,shard_suffix
+ );
+
END
$$;
--- We need a separate function for this, as we call create_table only once but need to add
--- those constraints to each partition which gets created
-CREATE OR REPLACE FUNCTION add_constraints_to_wire_targets_partition(
+
+CREATE OR REPLACE FUNCTION constrain_table_wire_targets(
IN partition_suffix VARCHAR
)
RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
-
EXECUTE FORMAT (
'ALTER TABLE wire_targets_' || partition_suffix || ' '
'ADD CONSTRAINT wire_targets_' || partition_suffix || '_wire_target_serial_id_key '
@@ -64,4 +79,9 @@ INSERT INTO exchange_tables
,'exchange-0002'
,'create'
,TRUE
+ ,FALSE),
+ ('wire_targets'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
,FALSE);