diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-11-27 14:45:01 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-11-27 14:45:01 +0100 |
commit | 4f75bcdca35b1ce8aa1f3db444c63f4763e28301 (patch) | |
tree | 0db42c55f3d35806f1343ce8e9dfbd140ff180cb /src/exchangedb/0002-purse_decision.sql | |
parent | a322770d290cae69e7d2f7629ee575e068254428 (diff) |
more work on SQL refactoring
Diffstat (limited to 'src/exchangedb/0002-purse_decision.sql')
-rw-r--r-- | src/exchangedb/0002-purse_decision.sql | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/exchangedb/0002-purse_decision.sql b/src/exchangedb/0002-purse_decision.sql index 2039cd931..f7a82810b 100644 --- a/src/exchangedb/0002-purse_decision.sql +++ b/src/exchangedb/0002-purse_decision.sql @@ -15,7 +15,7 @@ -- -CREATE OR REPLACE FUNCTION create_table_purse_decision( +CREATE FUNCTION create_table_purse_decision( IN shard_suffix VARCHAR DEFAULT NULL ) RETURNS VOID @@ -24,10 +24,9 @@ AS $$ DECLARE table_name VARCHAR DEFAULT 'purse_decision'; BEGIN - PERFORM create_partitioned_table( - 'CREATE TABLE IF NOT EXISTS %I ' - '(purse_decision_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE + 'CREATE TABLE %I ' + '(purse_decision_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' ',action_timestamp INT8 NOT NULL' ',refunded BOOL NOT NULL' @@ -37,23 +36,34 @@ BEGIN ,'PARTITION BY HASH (purse_pub)' ,shard_suffix ); - - table_name = concat_ws('_', table_name, shard_suffix); - + PERFORM comment_partitioned_table( + 'Purses that were decided upon (refund or merge)' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( + 'Public key of the purse' + ,'purse_pub' + ,table_name + ,shard_suffix + ); END $$; -CREATE OR REPLACE FUNCTION add_constraints_to_purse_decision_partition( +CREATE FUNCTION constrain_table_purse_decision( IN partition_suffix VARCHAR ) RETURNS VOID LANGUAGE plpgsql AS $$ +DECLARE + table_name VARCHAR DEFAULT 'purse_decision'; BEGIN + table_name = concat_ws('_', table_name, shard_suffix); EXECUTE FORMAT ( - 'ALTER TABLE purse_decision_' || partition_suffix || ' ' - 'ADD CONSTRAINT purse_decision_' || partition_suffix || '_purse_action_serial_id_key ' - 'UNIQUE (purse_decision_serial_id) ' + 'ALTER TABLE ' || table_name || + ' ADD CONSTRAINT ' || table_name || '_purse_action_serial_id_key' + ' UNIQUE (purse_decision_serial_id) ' ); END $$; @@ -70,4 +80,9 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'create' ,TRUE + ,FALSE), + ('purse_decision' + ,'exchange-0002' + ,'constrain' + ,TRUE ,FALSE); |