aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/0002-history_requests.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/0002-history_requests.sql')
-rw-r--r--src/exchangedb/0002-history_requests.sql27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/exchangedb/0002-history_requests.sql b/src/exchangedb/0002-history_requests.sql
index 5cd5c7b7b..853a435d4 100644
--- a/src/exchangedb/0002-history_requests.sql
+++ b/src/exchangedb/0002-history_requests.sql
@@ -26,7 +26,7 @@ DECLARE
BEGIN
PERFORM create_partitioned_table(
'CREATE TABLE %I '
- '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
+ '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
',request_timestamp INT8 NOT NULL'
',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
@@ -64,6 +64,26 @@ BEGIN
END $$;
+CREATE FUNCTION constrain_table_history_requests(
+ IN partition_suffix VARCHAR
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ partition_name VARCHAR;
+BEGIN
+ partition_name = concat_ws('_', 'history_requests', partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name ||
+ ' ADD CONSTRAINT ' || partition_name || '_serial_id'
+ ' UNIQUE (history_request_serial_id)'
+ );
+END
+$$;
+
+
CREATE FUNCTION foreign_table_history_requests()
RETURNS VOID
LANGUAGE plpgsql
@@ -94,6 +114,11 @@ INSERT INTO exchange_tables
,FALSE),
('history_requests'
,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('history_requests'
+ ,'exchange-0002'
,'foreign'
,TRUE
,FALSE);