diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-12-27 02:25:45 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-12-27 02:25:45 +0100 |
commit | 42e2726f43fcc497ca905fcd5f61758aa528f353 (patch) | |
tree | 3e58967c263549cb99d3aae36d94b65aaa2f60d9 /src/exchangedb/0003-purse_deletion.sql | |
parent | 0a40f484008e801870871f5a6ddac633dc990cd2 (diff) | |
download | exchange-42e2726f43fcc497ca905fcd5f61758aa528f353.tar.xz |
-work on v3 exchangedb schema
Diffstat (limited to 'src/exchangedb/0003-purse_deletion.sql')
-rw-r--r-- | src/exchangedb/0003-purse_deletion.sql | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/src/exchangedb/0003-purse_deletion.sql b/src/exchangedb/0003-purse_deletion.sql index e655ee613..5434a334e 100644 --- a/src/exchangedb/0003-purse_deletion.sql +++ b/src/exchangedb/0003-purse_deletion.sql @@ -15,60 +15,82 @@ -- CREATE OR REPLACE FUNCTION create_table_purse_deletion( - IN shard_suffix VARCHAR DEFAULT NULL + IN partition_suffix VARCHAR DEFAULT NULL ) RETURNS VOID LANGUAGE plpgsql AS $$ +DECLARE + table_name VARCHAR DEFAULT 'purse_deletion'; BEGIN PERFORM create_partitioned_table( 'CREATE TABLE IF NOT EXISTS %I' - '(purse_deletion_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE' + '(purse_deletion_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' ',purse_sig BYTEA CHECK (LENGTH(purse_sig)=64)' - ',XXX VARCHAR NOT NULL' + ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' ') %s ;' - ,'purse_deletion' - ,'PARTITION BY HASH (XXX)' - ,shard_suffix + ,table_name + ,'PARTITION BY HASH (purse_pub)' + ,partition_suffix ); - COMMENT ON TABLE purse_deletion - IS 'signatures affirming explicit purse deletions'; - COMMENT ON COLUMN purse_deletion.purse_sig - IS 'signature of type XXX'; -END -$$; + PERFORM comment_partitioned_table( + 'signatures affirming explicit purse deletions' + ,table_name + ,partition_suffix + ); + PERFORM comment_partitioned_column( + 'signature of type WALLET_PURSE_DELETE' + ,'purse_sig' + ,table_name + ,partition_suffix + ); +END $$; + COMMENT ON FUNCTION create_table_purse_deletion IS 'Creates the purse_deletion table'; + CREATE OR REPLACE FUNCTION constrain_table_purse_deletion( IN partition_suffix VARCHAR ) RETURNS void LANGUAGE plpgsql AS $$ +DECLARE + table_name VARCHAR DEFAULT 'purse_deletion'; BEGIN + table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( - 'ALTER TABLE purse_deletion_' || partition_suffix || ' ' - 'ADD CONSTRAINT purse_deletion_' || partition_suffix || '_XXX ' - 'UNIQUE (XXX)' + 'ALTER TABLE ' || table_name || + ' ADD CONSTRAINT ' || table_name || '_delete_serial_key ' + 'UNIQUE (purse_deletion_serial_id)' ); -END -$$; +END $$; -CREATE OR REPLACE FUNCTION alter_create_was_deleted_table_purse_requests ( + +CREATE OR REPLACE FUNCTION create_table_purse_requests_was_deleted ( IN partition_suffix VARCHAR ) RETURNS void LANGUAGE plpgsql AS $$ +DECLARE + table_name VARCHAR DEFAULT 'purse_requests'; BEGIN + table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( - 'ALTER TABLE purse_requests_' || partition_suffix || + 'ALTER TABLE ' || table_name || ' ADD COLUMN' ' was_deleted BOOLEAN NOT NULL DEFAULT(FALSE)' ); -END -$$; + PERFORM comment_partitioned_column( + 'TRUE if the purse was explicitly deleted (purse must have an entry in the purse_deletion table)' + ,'was_deleted' + ,table_name + ,partition_suffix + ); +END $$; + INSERT INTO exchange_tables (name @@ -78,17 +100,17 @@ INSERT INTO exchange_tables ,by_range) VALUES ('purse_deletion' - ,'exchange-0002' + ,'exchange-0003' ,'create' ,TRUE ,FALSE), ('purse_deletion' - ,'exchange-0002' + ,'exchange-0003' ,'constrain' ,TRUE ,FALSE), - ('purse_requests' - ,'exchange-0002' - ,'alter_create_was_deleted' + ('purse_requests_was_deleted' + ,'exchange-0003' + ,'create' ,TRUE ,FALSE); |