aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/0002-wire_targets.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-11-27 21:21:04 +0100
committerChristian Grothoff <christian@grothoff.org>2022-11-27 21:21:04 +0100
commitcf2e37cd876651e799893e8fe5babb51a9e12dd7 (patch)
tree437047cc646fb1a3a86f4226fd5460bbe2b0c530 /src/exchangedb/0002-wire_targets.sql
parentf2ba02aab2b9bbd976107ecc4ac7e7d657a9d73a (diff)
more work on SQL refactoring
Diffstat (limited to 'src/exchangedb/0002-wire_targets.sql')
-rw-r--r--src/exchangedb/0002-wire_targets.sql20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/exchangedb/0002-wire_targets.sql b/src/exchangedb/0002-wire_targets.sql
index afb9197af..5e5421085 100644
--- a/src/exchangedb/0002-wire_targets.sql
+++ b/src/exchangedb/0002-wire_targets.sql
@@ -15,7 +15,7 @@
--
CREATE FUNCTION create_table_wire_targets(
- IN shard_suffix VARCHAR DEFAULT NULL
+ IN partition_suffix VARCHAR DEFAULT NULL
)
RETURNS VOID
LANGUAGE plpgsql
@@ -29,23 +29,24 @@ BEGIN
') %s ;'
,'wire_targets'
,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
+ ,partition_suffix
);
PERFORM comment_partitioned_table(
'All senders and recipients of money via the exchange'
,'wire_targets'
- ,shard_suffix
+ ,partition_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
+ ,partition_suffix
);
PERFORM comment_partitioned_column(
'Unsalted hash of payto_uri'
,'wire_target_h_payto'
- ,shard_suffix
+ ,'wire_targets'
+ ,partition_suffix
);
END $$;
@@ -56,11 +57,14 @@ CREATE FUNCTION constrain_table_wire_targets(
RETURNS void
LANGUAGE plpgsql
AS $$
+DECLARE
+ table_name VARCHAR DEFAULT 'wire_targets';
BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
EXECUTE FORMAT (
- 'ALTER TABLE wire_targets_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_targets_' || partition_suffix || '_wire_target_serial_id_key '
- 'UNIQUE (wire_target_serial_id)'
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wire_target_serial_id_key'
+ ' UNIQUE (wire_target_serial_id)'
);
END
$$;