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-prewire.sql | |
parent | a322770d290cae69e7d2f7629ee575e068254428 (diff) |
more work on SQL refactoring
Diffstat (limited to 'src/exchangedb/0002-prewire.sql')
-rw-r--r-- | src/exchangedb/0002-prewire.sql | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/src/exchangedb/0002-prewire.sql b/src/exchangedb/0002-prewire.sql index e26475c12..fb8dc2212 100644 --- a/src/exchangedb/0002-prewire.sql +++ b/src/exchangedb/0002-prewire.sql @@ -14,8 +14,8 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -CREATE OR REPLACE FUNCTION create_table_prewire( - IN shard_suffix VARCHAR DEFAULT NULL +CREATE FUNCTION create_table_prewire( + IN partition_suffix VARCHAR DEFAULT NULL ) RETURNS VOID LANGUAGE plpgsql @@ -23,9 +23,8 @@ AS $$ DECLARE table_name VARCHAR DEFAULT 'prewire'; BEGIN - PERFORM create_partitioned_table( - 'CREATE TABLE IF NOT EXISTS %I' + 'CREATE TABLE %I' '(prewire_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY' ',wire_method TEXT NOT NULL' ',finished BOOLEAN NOT NULL DEFAULT false' @@ -34,13 +33,47 @@ BEGIN ') %s ;' ,table_name ,'PARTITION BY HASH (prewire_uuid)' - ,shard_suffix + ,partition_suffix + ); + PERFORM comment_partitioned_table( + 'pre-commit data for wire transfers we are about to execute' + ,table_name + ,partition_suffix ); + PERFORM comment_partitioned_column( + 'set to TRUE if the bank responded with a non-transient failure to our transfer request' + ,'failed' + ,table_name + ,partition_suffix + ); + PERFORM comment_partitioned_column( + 'set to TRUE once bank confirmed receiving the wire transfer request' + ,'finished' + ,table_name + ,partition_suffix + ); + PERFORM comment_partitioned_column( + 'serialized data to send to the bank to execute the wire transfer' + ,'buf' + ,table_name + ,partition_suffix + ); +END +$$; - table_name = concat_ws('_', table_name, shard_suffix); +CREATE FUNCTION constrain_table_prewire( + IN partition_suffix VARCHAR DEFAULT NULL +) +RETURNS VOID +LANGUAGE plpgsql +AS $$ +DECLARE + table_name VARCHAR DEFAULT 'prewire'; +BEGIN + table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( - 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_finished_index ' + 'CREATE INDEX ' || table_name || '_by_finished_index ' 'ON ' || table_name || ' ' '(finished);' ); @@ -50,7 +83,7 @@ BEGIN ); -- FIXME: find a way to combine these two indices? EXECUTE FORMAT ( - 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_failed_finished_index ' + 'CREATE INDEX ' || table_name || '_by_failed_finished_index ' 'ON ' || table_name || ' ' '(failed,finished);' ); @@ -58,7 +91,6 @@ BEGIN 'COMMENT ON INDEX ' || table_name || '_by_failed_finished_index ' 'IS ' || quote_literal('for wire_prepare_data_get') || ';' ); - END $$; @@ -74,4 +106,9 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'create' ,TRUE + ,FALSE), + ('prewire' + ,'exchange-0002' + ,'constrain' + ,TRUE ,FALSE); |