diff options
Diffstat (limited to 'src/exchangedb/0002-reserves_close.sql')
-rw-r--r-- | src/exchangedb/0002-reserves_close.sql | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/exchangedb/0002-reserves_close.sql b/src/exchangedb/0002-reserves_close.sql index d08c961fe..b68550a78 100644 --- a/src/exchangedb/0002-reserves_close.sql +++ b/src/exchangedb/0002-reserves_close.sql @@ -14,7 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -CREATE OR REPLACE FUNCTION create_table_reserves_close( +CREATE FUNCTION create_table_reserves_close( IN shard_suffix VARCHAR DEFAULT NULL ) RETURNS VOID @@ -23,9 +23,8 @@ AS $$ DECLARE table_name VARCHAR default 'reserves_close'; BEGIN - PERFORM create_partitioned_table( - 'CREATE TABLE IF NOT EXISTS %I' + 'CREATE TABLE %I' '(close_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE / PRIMARY KEY' ',reserve_pub BYTEA NOT NULL' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE' ',execution_date INT8 NOT NULL' @@ -41,33 +40,40 @@ BEGIN ,'PARTITION BY HASH (reserve_pub)' ,shard_suffix ); - - table_name = concat_ws('_', table_name, shard_suffix); - - EXECUTE FORMAT ( - 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_close_uuid_index ' - 'ON ' || table_name || ' ' - '(close_uuid);' + PERFORM comment_partitioned_table( + 'wire transfers executed by the reserve to close reserves' + ,table_name + ,shard_suffix ); - EXECUTE FORMAT ( - 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub_index ' - 'ON ' || table_name || ' ' - '(reserve_pub);' + PERFORM comment_partitioned_column( + 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.' + ,'wire_target_h_payto' + ,table_name + ,shard_suffix ); END $$; -CREATE OR REPLACE FUNCTION add_constraints_to_reserves_close_partition( + +CREATE FUNCTION constrain_table_reserves_close( IN partition_suffix VARCHAR ) RETURNS void LANGUAGE plpgsql AS $$ +DECLARE + table_name VARCHAR default 'reserves_close'; BEGIN + table_name = concat_ws('_', table_name, shard_suffix); + EXECUTE FORMAT ( + 'ALTER TABLE ' || table_name || ' ' + 'ADD CONSTRAINT ' || table_name || '_close_uuid_pkey ' + 'PRIMARY KEY (close_uuid)' + ); EXECUTE FORMAT ( - 'ALTER TABLE reserves_close_' || partition_suffix || ' ' - 'ADD CONSTRAINT reserves_close_' || partition_suffix || '_close_uuid_pkey ' - 'PRIMARY KEY (close_uuid)' + 'CREATE INDEX ' || table_name || '_by_reserve_pub_index ' + 'ON ' || table_name || ' ' + '(reserve_pub);' ); END $$; @@ -84,4 +90,9 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'create' ,TRUE + ,FALSE), + ('reserves_close' + ,'exchange-0002' + ,'constrain' + ,TRUE ,FALSE); |