diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-11-27 15:31:39 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-11-27 15:31:39 +0100 |
commit | 2eff222c524fa3b5ce2dd4a636aaec8dfb0862c7 (patch) | |
tree | fa730c5e13b1e5914c57770a431b6485ca6807fd /src/exchangedb/0002-wads_in.sql | |
parent | 85ce53a49b23fd651b07cea9b39fa0a830b3c9a0 (diff) |
more work on SQL refactoring
Diffstat (limited to 'src/exchangedb/0002-wads_in.sql')
-rw-r--r-- | src/exchangedb/0002-wads_in.sql | 76 |
1 files changed, 55 insertions, 21 deletions
diff --git a/src/exchangedb/0002-wads_in.sql b/src/exchangedb/0002-wads_in.sql index ca1466e05..dbbb02a7d 100644 --- a/src/exchangedb/0002-wads_in.sql +++ b/src/exchangedb/0002-wads_in.sql @@ -14,7 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -CREATE OR REPLACE FUNCTION create_table_wads_in( +CREATE FUNCTION create_table_wads_in( IN shard_suffix VARCHAR DEFAULT NULL ) RETURNS VOID @@ -23,41 +23,70 @@ AS $$ DECLARE table_name VARCHAR DEFAULT 'wads_in'; BEGIN - PERFORM create_partitioned_table( - 'CREATE TABLE IF NOT EXISTS %I ' - '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE - ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)' - ',origin_exchange_url TEXT NOT NULL' - ',amount_val INT8 NOT NULL' - ',amount_frac INT4 NOT NULL' - ',arrival_time INT8 NOT NULL' - ',UNIQUE (wad_id, origin_exchange_url)' - ') %s ;' + 'CREATE TABLE %I ' + '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' + ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)' + ',origin_exchange_url TEXT NOT NULL' + ',amount_val INT8 NOT NULL' + ',amount_frac INT4 NOT NULL' + ',arrival_time INT8 NOT NULL' + ',UNIQUE (wad_id, origin_exchange_url)' + ') %s ;' ,table_name ,'PARTITION BY HASH (wad_id)' ,shard_suffix ); + PERFORM comment_partitioned_table( + 'Incoming exchange-to-exchange wad wire transfers' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( + 'Unique identifier of the wad, part of the wire transfer subject' + ,'wad_id' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( + 'Base URL of the originating URL, also part of the wire transfer subject' + ,'origin_exchange_url' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( + 'Actual amount that was received by our exchange' + ,'amount_val' + ,table_name + ,shard_suffix + ); + PERFORM comment_partitioned_column( + 'Time when the wad was received' + ,'arrival_time' + ,table_name + ,shard_suffix + ); +END $$; -END -$$; -CREATE OR REPLACE FUNCTION add_constraints_to_wads_in_partition( +CREATE FUNCTION constrain_table_wads_in( IN partition_suffix VARCHAR ) RETURNS VOID LANGUAGE plpgsql AS $$ +DECLARE + table_name VARCHAR DEFAULT 'wads_in'; BEGIN + table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( - 'ALTER TABLE wads_in_' || partition_suffix || ' ' - 'ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_in_serial_id_key ' - 'UNIQUE (wad_in_serial_id) ' - ',ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_is_origin_exchange_url_key ' - 'UNIQUE (wad_id, origin_exchange_url) ' + 'ALTER TABLE ' || table_name || + ' ADD CONSTRAINT ' || table_name || '_wad_in_serial_id_key' + ' UNIQUE (wad_in_serial_id) ' + ',ADD CONSTRAINT ' || table_name || '_wad_is_origin_exchange_url_key' + ' UNIQUE (wad_id, origin_exchange_url) ' ); -END -$$; +END $$; INSERT INTO exchange_tables @@ -71,4 +100,9 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'create' ,TRUE + ,FALSE), + ('wads_in' + ,'exchange-0002' + ,'constrain' + ,TRUE ,FALSE); |