commit 659b1aaac82b57ff25cb26fcf34ba3c9b333b653 parent 97f3e30c3d4081a6765c914c94b6cbf3a75110f3 Author: Christian Grothoff <christian@grothoff.org> Date: Thu, 8 Feb 2024 00:05:39 +0100 clean up SQL logic a bit more Diffstat:
11 files changed, 12 insertions(+), 28 deletions(-)
diff --git a/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql b/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql @@ -14,8 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; -CREATE TABLE IF NOT EXISTS auditor_amount_arithmetic_inconsistency +CREATE TABLE auditor_amount_arithmetic_inconsistency ( row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY, operation BYTEA, @@ -24,4 +23,4 @@ CREATE TABLE IF NOT EXISTS auditor_amount_arithmetic_inconsistency profitable BOOLEAN ); COMMENT ON TABLE auditor_amount_arithmetic_inconsistency - IS 'Report a (serious) inconsistency in the exchange''s database with respect to calculations involving amounts'; -\ No newline at end of file + IS 'Report a (serious) inconsistency in the exchange''s database with respect to calculations involving amounts'; diff --git a/src/auditordb/0002-auditor_balances.sql b/src/auditordb/0002-auditor_balances.sql @@ -14,7 +14,6 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; CREATE TABLE IF NOT EXISTS auditor_balances ( balance_key TEXT PRIMARY KEY NOT NULL diff --git a/src/auditordb/0002-auditor_denomination_pending.sql b/src/auditordb/0002-auditor_denomination_pending.sql @@ -14,8 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; -CREATE TABLE IF NOT EXISTS auditor_denomination_pending +CREATE TABLE auditor_denomination_pending (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64) ,denom_balance taler_amount NOT NULL ,denom_loss taler_amount NOT NULL diff --git a/src/auditordb/0002-auditor_deposit_confirmations.sql b/src/auditordb/0002-auditor_deposit_confirmations.sql @@ -14,9 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; -DROP TABLE IF EXISTS deposit_confirmations; -CREATE TABLE IF NOT EXISTS auditor_deposit_confirmations +CREATE TABLE auditor_deposit_confirmations (deposit_confirmation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64) ,h_policy BYTEA NOT NULL CHECK (LENGTH(h_policy)=64) @@ -57,4 +55,4 @@ COMMENT ON FUNCTION auditor_new_transactions_trigger() CREATE TRIGGER auditor_notify_helper_deposits AFTER INSERT ON auditor.auditor_deposit_confirmations -EXECUTE PROCEDURE auditor_new_transactions_trigger(); -\ No newline at end of file +EXECUTE PROCEDURE auditor_new_transactions_trigger(); diff --git a/src/auditordb/0002-auditor_exchange_signkeys.sql b/src/auditordb/0002-auditor_exchange_signkeys.sql @@ -14,8 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -DROP TABLE IF EXISTS auditor_exchange_signkeys; -CREATE TABLE IF NOT EXISTS auditor_exchange_signkeys +CREATE TABLE auditor_exchange_signkeys (exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32) ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64) ,ep_valid_from INT8 NOT NULL diff --git a/src/auditordb/0002-auditor_historic_denomination_revenue.sql b/src/auditordb/0002-auditor_historic_denomination_revenue.sql @@ -14,8 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; -CREATE TABLE IF NOT EXISTS auditor_historic_denomination_revenue +CREATE TABLE auditor_historic_denomination_revenue (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64) ,revenue_timestamp INT8 NOT NULL ,revenue_balance taler_amount NOT NULL diff --git a/src/auditordb/0002-auditor_purses.sql b/src/auditordb/0002-auditor_purses.sql @@ -14,8 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; -CREATE TABLE IF NOT EXISTS auditor_purses +CREATE TABLE auditor_purses (auditor_purses_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE ,purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32) ,balance taler_amount NOT NULL DEFAULT(0,0) diff --git a/src/auditordb/0002-auditor_reserves.sql b/src/auditordb/0002-auditor_reserves.sql @@ -14,8 +14,7 @@ -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- -SET search_path TO auditor; -CREATE TABLE IF NOT EXISTS auditor_reserves +CREATE TABLE auditor_reserves (auditor_reserves_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE ,reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32) ,reserve_balance taler_amount NOT NULL diff --git a/src/auditordb/auditor-0002.sql.in b/src/auditordb/auditor-0002.sql.in @@ -16,12 +16,8 @@ BEGIN; --- move later into auditor-0001.sql -CREATE SCHEMA IF NOT EXISTS auditor; -COMMENT ON SCHEMA auditor IS 'taler-auditor data'; - - SELECT _v.register_patch('auditor-0002', NULL, NULL); + SET search_path TO auditor; DO $$ BEGIN diff --git a/src/auditordb/drop.sql b/src/auditordb/drop.sql @@ -17,10 +17,8 @@ -- Everything in one big transaction BEGIN; - --- Drop versioning (auditor-0001.sql) SELECT _v.unregister_patch('auditor-0001'); --- SELECT _v.unregister_patch('auditor-0002'); +SELECT _v.unregister_patch('auditor-0002'); DROP SCHEMA auditor CASCADE; -- And we're out of here... diff --git a/src/auditordb/restart.sql b/src/auditordb/restart.sql @@ -31,6 +31,7 @@ SET search_path TO auditor; -- Unlike the other SQL files, it SHOULD be updated to reflect the -- latest requirements for dropping tables. +DELETE FROM auditor_amount_arithmetic_inconsistency; DELETE FROM auditor_balances; DELETE FROM auditor_denomination_pending; DELETE FROM auditor_historic_denomination_revenue;