summaryrefslogtreecommitdiff
path: root/src/exchangedb/0003-purse_actions.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-11-27 00:16:00 +0100
committerChristian Grothoff <christian@grothoff.org>2022-11-27 00:16:00 +0100
commit9580dd19c23e5591cc022dce717eca7bc745c5b0 (patch)
tree8c63bab63f6cf7673dd68fc214ea8c4022f46ef8 /src/exchangedb/0003-purse_actions.sql
parent746a8a0cdb7b3494230d41e870173936120cd34b (diff)
downloadexchange-9580dd19c23e5591cc022dce717eca7bc745c5b0.tar.gz
exchange-9580dd19c23e5591cc022dce717eca7bc745c5b0.tar.bz2
exchange-9580dd19c23e5591cc022dce717eca7bc745c5b0.zip
intermediate step in major SQL refactoring (not done at all)
Diffstat (limited to 'src/exchangedb/0003-purse_actions.sql')
-rw-r--r--src/exchangedb/0003-purse_actions.sql60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/exchangedb/0003-purse_actions.sql b/src/exchangedb/0003-purse_actions.sql
new file mode 100644
index 000000000..df8eecea7
--- /dev/null
+++ b/src/exchangedb/0003-purse_actions.sql
@@ -0,0 +1,60 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE TABLE IF NOT EXISTS purse_actions
+ (purse_pub BYTEA NOT NULL PRIMARY KEY CHECK(LENGTH(purse_pub)=32)
+ ,action_date INT8 NOT NULL
+ ,partner_serial_id INT8
+ );
+COMMENT ON TABLE purse_actions
+ IS 'purses awaiting some action by the router';
+COMMENT ON COLUMN purse_actions.purse_pub
+ IS 'public (contract) key of the purse';
+COMMENT ON COLUMN purse_actions.action_date
+ IS 'when is the purse ready for action';
+COMMENT ON COLUMN purse_actions.partner_serial_id
+ IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
+
+CREATE INDEX IF NOT EXISTS purse_action_by_target
+ ON purse_actions
+ (partner_serial_id,action_date);
+
+
+CREATE OR REPLACE FUNCTION purse_requests_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO
+ purse_actions
+ (purse_pub
+ ,action_date)
+ VALUES
+ (NEW.purse_pub
+ ,NEW.purse_expiration);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION purse_requests_insert_trigger()
+ IS 'When a purse is created, insert it into the purse_action table to take action when the purse expires.';
+
+CREATE TRIGGER purse_requests_on_insert
+ AFTER INSERT
+ ON purse_requests
+ FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
+COMMENT ON TRIGGER purse_requests_on_insert
+ ON purse_requests
+ IS 'Here we install an entry for the purse expiration.';