commit ac0db33c36e7c564440ad8b11778a74ef3550686
parent 0e02c014318916993ceb0436f985c1d4891bb06d
Author: Florian Dold <florian@dold.me>
Date: Wed, 6 May 2026 19:06:34 +0200
integrate SQL generation properly into the build system
Diffstat:
23 files changed, 577 insertions(+), 473 deletions(-)
diff --git a/meson.build b/meson.build
@@ -361,6 +361,7 @@ if not get_option('only-doc')
taler_prefix = get_option('prefix') / get_option('libdir')
+ # Default setup only does unit tests
add_test_setup(
'default',
env: [
@@ -370,6 +371,13 @@ if not get_option('only-doc')
exclude_suites: ['perf', 'installcheck', 'integrationtests'],
is_default: true,
)
+ add_test_setup(
+ 'all',
+ env: [
+ 'TALER_EXCHANGE_PREFIX=' + taler_prefix,
+ 'TALER_AUDITOR_PREFIX=' + taler_prefix,
+ ],
+ )
else
subdir('contrib')
if not get_option('disable-doc')
diff --git a/src/auditordb/0002-preamble.sql b/src/auditordb/0002-preamble.sql
@@ -0,0 +1,33 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2025 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/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('auditor-0002', NULL, NULL);
+
+SET search_path TO auditor;
+
+DO $$ BEGIN
+ CREATE TYPE taler_amount
+ AS
+ (val INT8
+ ,frac INT4
+ );
+ COMMENT ON TYPE taler_amount
+ IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
+EXCEPTION
+ WHEN duplicate_object THEN null;
+END $$;
diff --git a/src/auditordb/auditor-0002.sql.in b/src/auditordb/auditor-0002.sql.in
@@ -1,67 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2025 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/>
---
-
-BEGIN;
-
-SELECT _v.register_patch('auditor-0002', NULL, NULL);
-
-SET search_path TO auditor;
-
-DO $$ BEGIN
- CREATE TYPE taler_amount
- AS
- (val INT8
- ,frac INT4
- );
- COMMENT ON TYPE taler_amount
- IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
-EXCEPTION
- WHEN duplicate_object THEN null;
-END $$;
-
-#include "0002-auditor_amount_arithmetic_inconsistency.sql"
-#include "0002-auditor_bad_sig_losses.sql"
-#include "0002-auditor_balances.sql"
-#include "0002-auditor_closure_lags.sql"
-#include "0002-auditor_coin_inconsistency.sql"
-#include "0002-auditor_denomination_key_validity_withdraw_inconsistency.sql"
-#include "0002-auditor_denomination_pending.sql"
-#include "0002-auditor_denominations_without_sigs.sql"
-#include "0002-auditor_deposit_confirmations.sql"
-#include "0002-auditor_emergency.sql"
-#include "0002-auditor_emergency_by_count.sql"
-#include "0002-auditor_exchange_signkeys.sql"
-#include "0002-auditor_fee_time_inconsistency.sql"
-#include "0002-auditor_historic_denomination_revenue.sql"
-#include "0002-auditor_historic_reserve_summary.sql"
-#include "0002-auditor_misattribution_in_inconsistency.sql"
-#include "0002-auditor_progress.sql"
-#include "0002-auditor_purse_not_closed_inconsistencies.sql"
-#include "0002-auditor_purses.sql"
-#include "0002-auditor_refreshes_hanging.sql"
-#include "0002-auditor_reserve_balance_insufficient_inconsistency.sql"
-#include "0002-auditor_reserve_balance_summary_wrong_inconsistency.sql"
-#include "0002-auditor_reserve_in_inconsistency.sql"
-#include "0002-auditor_reserve_not_closed_inconsistency.sql"
-#include "0002-auditor_reserves.sql"
-#include "0002-auditor_row_inconsistency.sql"
-#include "0002-auditor_row_minor_inconsistencies.sql"
-#include "0002-auditor_wire_format_inconsistency.sql"
-#include "0002-auditor_wire_out_inconsistency.sql"
-#include "0002-auditor_pending_deposits.sql"
-#include "0002-auditor_early_aggregation.sql"
-
-COMMIT;
diff --git a/src/auditordb/commit.sql b/src/auditordb/commit.sql
@@ -0,0 +1,17 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2026 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/>
+--
+
+COMMIT;
diff --git a/src/auditordb/meson.build b/src/auditordb/meson.build
@@ -4,22 +4,68 @@ install_data('auditordb-postgres.conf', install_dir: pkgcfgdir)
sqldir = get_option('datadir') / 'taler-auditor' / 'sql'
-# FIXME possibly provide this output in the tgz through dist script
-run_command('make', '-f', 'Makefile.sql', 'all', check: true)
+procedures_sql = [
+ 'procedures-preamble.sql',
+ 'auditor_do_get_auditor_progress.sql',
+ 'auditor_do_get_balance.sql',
+ 'auditor_do_gc_auditor.sql',
+ 'commit.sql',
+]
+
+auditor_0002_sql = [
+ '0002-preamble.sql',
+ '0002-auditor_amount_arithmetic_inconsistency.sql',
+ '0002-auditor_bad_sig_losses.sql',
+ '0002-auditor_balances.sql',
+ '0002-auditor_closure_lags.sql',
+ '0002-auditor_coin_inconsistency.sql',
+ '0002-auditor_denomination_key_validity_withdraw_inconsistency.sql',
+ '0002-auditor_denomination_pending.sql',
+ '0002-auditor_denominations_without_sigs.sql',
+ '0002-auditor_deposit_confirmations.sql',
+ '0002-auditor_emergency.sql',
+ '0002-auditor_emergency_by_count.sql',
+ '0002-auditor_exchange_signkeys.sql',
+ '0002-auditor_fee_time_inconsistency.sql',
+ '0002-auditor_historic_denomination_revenue.sql',
+ '0002-auditor_historic_reserve_summary.sql',
+ '0002-auditor_misattribution_in_inconsistency.sql',
+ '0002-auditor_progress.sql',
+ '0002-auditor_purse_not_closed_inconsistencies.sql',
+ '0002-auditor_purses.sql',
+ '0002-auditor_refreshes_hanging.sql',
+ '0002-auditor_reserve_balance_insufficient_inconsistency.sql',
+ '0002-auditor_reserve_balance_summary_wrong_inconsistency.sql',
+ '0002-auditor_reserve_in_inconsistency.sql',
+ '0002-auditor_reserve_not_closed_inconsistency.sql',
+ '0002-auditor_reserves.sql',
+ '0002-auditor_row_inconsistency.sql',
+ '0002-auditor_row_minor_inconsistencies.sql',
+ '0002-auditor_wire_format_inconsistency.sql',
+ '0002-auditor_wire_out_inconsistency.sql',
+ '0002-auditor_pending_deposits.sql',
+ '0002-auditor_early_aggregation.sql',
+ 'commit.sql',
+]
-sqlfiles = [
- 'versioning.sql',
- 'auditor-0001.sql',
- 'auditor-0002.sql',
- 'drop.sql',
- 'restart.sql',
- 'procedures.sql',
+generated_sql = [
+ ['versioning.sql', ['versioning.sql']],
+ ['drop.sql', ['drop.sql']],
+ ['procedures.sql', procedures_sql],
+ ['auditor-0001.sql', ['auditor-0001.sql']],
+ ['auditor-0002.sql', auditor_0002_sql],
]
-install_data(sources: sqlfiles, install_dir: sqldir)
-# This makes meson copy the files into the build directory for testing
-foreach f : sqlfiles
- configure_file(input: f, output: f, copy: true)
+foreach g : generated_sql
+ custom_target(
+ 'gen-auditordb-' + g[0],
+ input: g[1],
+ output: g[0],
+ capture: true,
+ command: ['../exchangedb/sql-schema/amalgamate-sql.sh', '@INPUT@'],
+ install: true,
+ install_dir: sqldir,
+ )
endforeach
libtalerauditordb = library(
diff --git a/src/auditordb/procedures-preamble.sql b/src/auditordb/procedures-preamble.sql
@@ -0,0 +1,19 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 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/>
+--
+
+BEGIN;
+
+SET search_path TO auditor;
diff --git a/src/exchangedb/sql-schema/0002-preamble.sql b/src/exchangedb/sql-schema/0002-preamble.sql
@@ -0,0 +1,61 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 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/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0002', NULL, NULL);
+SET search_path TO exchange;
+
+CREATE DOMAIN gnunet_hashcode
+ AS BYTEA
+ CHECK(LENGTH(VALUE) = 32);
+
+CREATE TYPE taler_amount
+ AS
+ (val INT8
+ ,frac INT4
+ );
+COMMENT ON TYPE taler_amount
+ IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
+
+CREATE TYPE exchange_do_array_reserve_insert_return_type
+ AS
+ (transaction_duplicate BOOLEAN
+ ,ruuid INT8
+ );
+COMMENT ON TYPE exchange_do_array_reserve_insert_return_type
+ IS 'Return type for exchange_do_array_reserves_insert() stored procedure';
+
+CREATE TYPE exchange_do_select_deposits_missing_wire_return_type
+ AS
+ (
+ batch_deposit_serial_id INT8,
+ total_amount taler_amount,
+ wire_target_h_payto BYTEA,
+ deadline INT8
+ );
+COMMENT ON TYPE exchange_do_select_deposits_missing_wire_return_type
+ IS 'Return type for exchange_do_select_deposits_missing_wire';
+
+CREATE TYPE exchange_do_select_aggregations_above_serial_return_type
+ AS
+ (
+ batch_deposit_serial_id INT8,
+ aggregation_serial_id INT8,
+ total_amount taler_amount
+ );
+COMMENT ON TYPE exchange_do_select_aggregations_above_serial_return_type
+ IS 'Return type for exchange_do_select_aggregations_above_serial';
diff --git a/src/exchangedb/sql-schema/0003-preamble.sql b/src/exchangedb/sql-schema/0003-preamble.sql
@@ -0,0 +1,20 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2026 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/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0003', NULL, NULL);
+SET search_path TO exchange;
diff --git a/src/exchangedb/sql-schema/0004-preamble.sql b/src/exchangedb/sql-schema/0004-preamble.sql
@@ -0,0 +1,20 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2025 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/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0004', NULL, NULL);
+SET search_path TO exchange;
diff --git a/src/exchangedb/sql-schema/0009-preamble.sql b/src/exchangedb/sql-schema/0009-preamble.sql
@@ -0,0 +1,19 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2026 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/>
+--
+BEGIN;
+
+SELECT _v.register_patch('exchange-0009', NULL, NULL);
+SET search_path TO exchange;
diff --git a/src/exchangedb/sql-schema/0010-preamble.sql b/src/exchangedb/sql-schema/0010-preamble.sql
@@ -0,0 +1,20 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2026 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/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0010', NULL, NULL);
+SET search_path TO exchange;
diff --git a/src/exchangedb/sql-schema/Makefile.sql b/src/exchangedb/sql-schema/Makefile.sql
@@ -1,42 +0,0 @@
-procedures.sql: procedures.sql.in ../*.sql exchange_do_*.sql exchange_statistics_*.sql exchange_trigger_*.sql
- chmod +w $@ || true
- gcc -E -P -undef - < procedures.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
- chmod ugo-w $@
-
-exchange-0002.sql: exchange-0002.sql.in 0002-*.sql
- chmod +w $@ || true
- gcc -E -P -undef - < exchange-0002.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
- chmod ugo-w $@
-
-exchange-0003.sql: exchange-0003.sql.in 0003-*.sql
- chmod +w $@ || true
- gcc -E -P -undef - < exchange-0003.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
- chmod ugo-w $@
-
-exchange-0004.sql: exchange-0004.sql.in 0004-*.sql
- chmod +w $@ || true
- gcc -E -P -undef - < exchange-0004.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
- chmod ugo-w $@
-
-exchange-0009.sql: exchange-0009.sql.in 0009-*.sql
- chmod +w $@ || true
- gcc -E -P -undef - < exchange-0009.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
- chmod ugo-w $@
-
-exchange-0010.sql: exchange-0010.sql.in 0010-*.sql
- chmod +w $@ || true
- gcc -E -P -undef - < exchange-0010.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
- chmod ugo-w $@
-
-CLEANFILES = \
- exchange-0002.sql \
- exchange-0003.sql \
- exchange-0004.sql \
- exchange-0009.sql \
- exchange-0010.sql \
- procedures.sql
-
-all: ${CLEANFILES}
-
-clean:
- rm ${CLEANFILES}
diff --git a/src/exchangedb/sql-schema/amalgamate-sql.sh b/src/exchangedb/sql-schema/amalgamate-sql.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# This file is part of TALER
+# Copyright (C) 2026 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/>
+
+set -eu
+
+if [ $# -lt 1 ]; then
+ echo "Usage: $0 SQLFILES..." >&2
+ exit 1
+fi
+
+cat <<'EOF'
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2025 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/>
+--
+EOF
+
+for x in $@; do
+ echo -- generated from $x
+ # Remove SQL comments and empty lines
+ cat $x | sed -e "s/--.*//" | awk 'NF'
+done
diff --git a/src/exchangedb/sql-schema/commit.sql b/src/exchangedb/sql-schema/commit.sql
@@ -0,0 +1,15 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2026 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/>
+COMMIT;
diff --git a/src/exchangedb/sql-schema/exchange-0002.sql.in b/src/exchangedb/sql-schema/exchange-0002.sql.in
@@ -1,134 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2023 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/>
---
-
-BEGIN;
-
-SELECT _v.register_patch('exchange-0002', NULL, NULL);
-SET search_path TO exchange;
-
-CREATE DOMAIN gnunet_hashcode
- AS BYTEA
- CHECK(LENGTH(VALUE) = 32);
-
-CREATE TYPE taler_amount
- AS
- (val INT8
- ,frac INT4
- );
-COMMENT ON TYPE taler_amount
- IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
-
-CREATE TYPE exchange_do_array_reserve_insert_return_type
- AS
- (transaction_duplicate BOOLEAN
- ,ruuid INT8
- );
-COMMENT ON TYPE exchange_do_array_reserve_insert_return_type
- IS 'Return type for exchange_do_array_reserves_insert() stored procedure';
-
-CREATE TYPE exchange_do_select_deposits_missing_wire_return_type
- AS
- (
- batch_deposit_serial_id INT8,
- total_amount taler_amount,
- wire_target_h_payto BYTEA,
- deadline INT8
- );
-COMMENT ON TYPE exchange_do_select_deposits_missing_wire_return_type
- IS 'Return type for exchange_do_select_deposits_missing_wire';
-
-CREATE TYPE exchange_do_select_aggregations_above_serial_return_type
- AS
- (
- batch_deposit_serial_id INT8,
- aggregation_serial_id INT8,
- total_amount taler_amount
- );
-COMMENT ON TYPE exchange_do_select_aggregations_above_serial_return_type
- IS 'Return type for exchange_do_select_aggregations_above_serial';
-
-
-#include "0002-denominations.sql"
-#include "0002-denomination_revocations.sql"
-#include "0002-wire_targets.sql"
-#include "0002-kyc_alerts.sql"
-#include "0002-wire_fee.sql"
-#include "0002-global_fee.sql"
-#include "0002-wire_accounts.sql"
-#include "0002-auditors.sql"
-#include "0002-auditor_denom_sigs.sql"
-#include "0002-exchange_sign_keys.sql"
-#include "0002-signkey_revocations.sql"
-#include "0002-extensions.sql"
-#include "0002-policy_fulfillments.sql"
-#include "0002-policy_details.sql"
-#include "0002-profit_drains.sql"
-#include "0002-legitimization_measures.sql"
-#include "0002-legitimization_outcomes.sql"
-#include "0002-legitimization_processes.sql"
-
-
-#include "0002-reserves.sql"
-#include "0002-reserve_history.sql"
-#include "0002-reserves_in.sql"
-#include "0002-reserves_close.sql"
-#include "0002-close_requests.sql"
-#include "0002-reserves_open_deposits.sql"
-#include "0002-reserves_open_requests.sql"
-#include "0002-known_coins.sql"
-#include "0002-coin_history.sql"
-#include "0002-batch_deposits.sql"
-#include "0002-coin_deposits.sql"
-#include "0002-refunds.sql"
-#include "0002-wire_out.sql"
-#include "0002-aggregation_transient.sql"
-#include "0002-aggregation_tracking.sql"
-#include "0002-unique_refresh_blinding_seed.sql"
-#include "0002-refresh.sql"
-#include "0002-unique_withdraw_blinding_seed.sql"
-#include "0002-withdraw.sql"
-#include "0002-recoup.sql"
-#include "0002-recoup_refresh.sql"
-#include "0002-prewire.sql"
-#include "0002-cs_nonce_locks.sql"
-#include "0002-purse_requests.sql"
-#include "0002-purse_merges.sql"
-#include "0002-account_merges.sql"
-#include "0002-purse_decision.sql"
-#include "0002-contracts.sql"
-#include "0002-history_requests.sql"
-#include "0002-purse_deposits.sql"
-#include "0002-wads_in.sql"
-#include "0002-wad_in_entries.sql"
-#include "0002-wads_out.sql"
-#include "0002-wad_out_entries.sql"
-#include "0002-work_shards.sql"
-#include "0002-revolving_work_shards.sql"
-#include "0002-partners.sql"
-#include "0002-partner_accounts.sql"
-#include "0002-purse_actions.sql"
-#include "0002-purse_deletion.sql"
-
-#include "0002-kyc_attributes.sql"
-
-#include "0002-kycauths_in.sql"
-#include "0002-kyc_events.sql"
-#include "0002-aml_staff.sql"
-#include "0002-aml_history.sql"
-
-#include "0002-statistics.sql"
-
-COMMIT;
diff --git a/src/exchangedb/sql-schema/exchange-0003.sql.in b/src/exchangedb/sql-schema/exchange-0003.sql.in
@@ -1,34 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2025 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/>
---
-
-BEGIN;
-
-SELECT _v.register_patch('exchange-0003', NULL, NULL);
-SET search_path TO exchange;
-
-#include "0003-kyc_targets.sql"
-#include "0003-legitimization_measures.sql"
-#include "0003-legitimization_outcomes.sql"
-#include "0003-legitimization_processes.sql"
--- Note that wire_targets MUST be after kyc_targets and
--- legitimization measures here,
--- as we first need to create kyc_targets and migrate the
--- data before dropping it in wire_targets!
-#include "0003-wire_targets.sql"
--- This table was already dead in v1.0, drop it for real
-#include "0003-reserves_out.sql"
-
-COMMIT;
diff --git a/src/exchangedb/sql-schema/exchange-0004.sql.in b/src/exchangedb/sql-schema/exchange-0004.sql.in
@@ -1,25 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2025 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/>
---
-
-BEGIN;
-
-SELECT _v.register_patch('exchange-0004', NULL, NULL);
-SET search_path TO exchange;
-
-#include "0004-kyc_attributes.sql"
-#include "0004-refresh.sql"
-
-COMMIT;
diff --git a/src/exchangedb/sql-schema/exchange-0009.sql.in b/src/exchangedb/sql-schema/exchange-0009.sql.in
@@ -1,24 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2026 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/>
---
-
-BEGIN;
-
-SELECT _v.register_patch('exchange-0009', NULL, NULL);
-SET search_path TO exchange;
-
-#include "0009-batch_deposits.sql"
-
-COMMIT;
diff --git a/src/exchangedb/sql-schema/exchange-0010.sql.in b/src/exchangedb/sql-schema/exchange-0010.sql.in
@@ -1,24 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2026 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/>
---
-
-BEGIN;
-
-SELECT _v.register_patch('exchange-0010', NULL, NULL);
-SET search_path TO exchange;
-
-#include "0010-wire_accounts.sql"
-
-COMMIT;
diff --git a/src/exchangedb/sql-schema/meson.build b/src/exchangedb/sql-schema/meson.build
@@ -1,30 +1,194 @@
+# This Makefile.am is in the public domain
+
sqldir = get_option('datadir') / 'taler-exchange' / 'sql'
-# FIXME possibly provide this output in the tgz through dist script
-run_command('make', '-f', 'Makefile.sql', 'all', check: true)
-
-sqlfiles = [
- 'auditor-triggers-0001.sql',
- 'benchmark-0001.sql',
- 'drop.sql',
- 'exchange-0001.sql',
- 'exchange-0002.sql',
- 'exchange-0003.sql',
- 'exchange-0004.sql',
- 'exchange-0005.sql',
- 'exchange-0006.sql',
- 'exchange-0007.sql',
- 'exchange-0008.sql',
- 'exchange-0009.sql',
- 'exchange-0010.sql',
- 'procedures.sql',
- 'tops-0001.sql',
- 'versioning.sql',
+procedures_sql = [
+ 'procedures-preamble.sql',
+ 'exchange_do_create_partitioned_table.sql',
+ 'exchange_do_comment_partitioned_table.sql',
+ 'exchange_do_comment_partitioned_column.sql',
+ 'exchange_do_create_tables.sql',
+ 'exchange_do_amount_specific.sql',
+ '../do_withdraw.sql',
+ '../do_refresh.sql',
+ '../do_deposit.sql',
+ '../do_check_deposit_idempotent.sql',
+ # dead!?
+ 'exchange_do_melt.sql',
+ '../select_batch_deposits_missing_wire.sql',
+ # dead!?
+ 'exchange_do_select_justification_for_missing_wire.sql',
+ '../do_refund.sql',
+ '../do_recoup.sql',
+ '../do_recoup_refresh.sql',
+ '../gc.sql',
+ '../do_purse_delete.sql',
+ '../do_purse_deposit.sql',
+ '../do_purse_merge.sql',
+ '../do_reserve_purse.sql',
+ '../expire_purse.sql',
+ '../insert_reserve_open_deposit.sql',
+ '../do_reserve_open.sql',
+ '../persist_policy_details.sql',
+ '../insert_aml_decision.sql',
+ '../insert_successor_measure.sql',
+ '../insert_aml_officer.sql',
+ '../reserves_in_insert.sql',
+ # semi-dead...
+ 'exchange_do_get_link_data.sql',
+ '../batch_ensure_coin_known.sql',
+ '../kycauth_in_insert.sql',
+ '../trigger_kyc_rule_for_account.sql',
+ '../lookup_kyc_requirement_by_row.sql',
+ '../insert_active_legitimization_measure.sql',
+ '../select_aggregations_above_serial.sql',
+ '../persist_kyc_attributes.sql',
+ '../insert_aml_program_failure.sql',
+ '../set_aml_lock.sql',
+ '../insert_sanction_list_hit.sql',
+ 'exchange_statistics_helpers.sql',
+ 'exchange_trigger_purse_requests_insert.sql',
+ 'exchange_trigger_withdraw_delete.sql',
+ 'exchange_trigger_withdraw_insert.sql',
+ 'exchange_trigger_reserves_in_insert.sql',
+ 'exchange_trigger_purse_decision_insert.sql',
+ '../get_kyc_rules.sql',
+ 'procedures-epilogue.sql',
+]
+
+
+exchange_0002_sql = [
+ '0002-preamble.sql',
+ '0002-denominations.sql',
+ '0002-denomination_revocations.sql',
+ '0002-wire_targets.sql',
+ '0002-kyc_alerts.sql',
+ '0002-wire_fee.sql',
+ '0002-global_fee.sql',
+ '0002-wire_accounts.sql',
+ '0002-auditors.sql',
+ '0002-auditor_denom_sigs.sql',
+ '0002-exchange_sign_keys.sql',
+ '0002-signkey_revocations.sql',
+ '0002-extensions.sql',
+ '0002-policy_fulfillments.sql',
+ '0002-policy_details.sql',
+ '0002-profit_drains.sql',
+ '0002-legitimization_measures.sql',
+ '0002-legitimization_outcomes.sql',
+ '0002-legitimization_processes.sql',
+ '0002-reserves.sql',
+ '0002-reserve_history.sql',
+ '0002-reserves_in.sql',
+ '0002-reserves_close.sql',
+ '0002-close_requests.sql',
+ '0002-reserves_open_deposits.sql',
+ '0002-reserves_open_requests.sql',
+ '0002-known_coins.sql',
+ '0002-coin_history.sql',
+ '0002-batch_deposits.sql',
+ '0002-coin_deposits.sql',
+ '0002-refunds.sql',
+ '0002-wire_out.sql',
+ '0002-aggregation_transient.sql',
+ '0002-aggregation_tracking.sql',
+ '0002-unique_refresh_blinding_seed.sql',
+ '0002-refresh.sql',
+ '0002-unique_withdraw_blinding_seed.sql',
+ '0002-withdraw.sql',
+ '0002-recoup.sql',
+ '0002-recoup_refresh.sql',
+ '0002-prewire.sql',
+ '0002-cs_nonce_locks.sql',
+ '0002-purse_requests.sql',
+ '0002-purse_merges.sql',
+ '0002-account_merges.sql',
+ '0002-purse_decision.sql',
+ '0002-contracts.sql',
+ '0002-history_requests.sql',
+ '0002-purse_deposits.sql',
+ '0002-wads_in.sql',
+ '0002-wad_in_entries.sql',
+ '0002-wads_out.sql',
+ '0002-wad_out_entries.sql',
+ '0002-work_shards.sql',
+ '0002-revolving_work_shards.sql',
+ '0002-partners.sql',
+ '0002-partner_accounts.sql',
+ '0002-purse_actions.sql',
+ '0002-purse_deletion.sql',
+ '0002-kyc_attributes.sql',
+ '0002-kycauths_in.sql',
+ '0002-kyc_events.sql',
+ '0002-aml_staff.sql',
+ '0002-aml_history.sql',
+ '0002-statistics.sql',
+ 'commit.sql',
+]
+
+exchange_0003_sql = [
+ '0003-preamble.sql',
+ '0003-kyc_targets.sql',
+ '0003-legitimization_measures.sql',
+ '0003-legitimization_outcomes.sql',
+ '0003-legitimization_processes.sql',
+ # Note that wire_targets MUST be after kyc_targets and
+ # legitimization measures here,
+ # as we first need to create kyc_targets and migrate the
+ # data before dropping it in wire_targets!
+ '0003-wire_targets.sql',
+ # This table was already dead in v1.0, drop it for real
+ '0003-reserves_out.sql',
+ 'commit.sql',
+]
+
+exchange_0004_sql = [
+ '0004-preamble.sql',
+ '0004-kyc_attributes.sql',
+ '0004-refresh.sql',
+ 'commit.sql',
+]
+
+exchange_0009_sql = [
+ '0009-preamble.sql',
+ '0009-batch_deposits.sql',
+ 'commit.sql',
]
-install_data(sources: sqlfiles, install_dir: sqldir)
+exchange_0010_sql = [
+ '0010-preamble.sql',
+ '0010-wire_accounts.sql',
+ 'commit.sql',
+]
-# This makes meson copy the files into the build directory for testing
-foreach f : sqlfiles
- configure_file(input: f, output: f, copy: true)
+generated_sql = [
+ ['auditor-triggers-0001.sql', ['auditor-triggers-0001.sql']],
+ ['versioning.sql', ['versioning.sql']],
+ ['drop.sql', ['drop.sql']],
+ ['procedures.sql', procedures_sql],
+ ['benchmark-0001.sql', ['benchmark-0001.sql']],
+ ['exchange-0001.sql', ['exchange-0001.sql']],
+ ['exchange-0002.sql', exchange_0002_sql],
+ ['exchange-0003.sql', exchange_0003_sql],
+ ['exchange-0004.sql', exchange_0004_sql],
+ ['exchange-0005.sql', ['exchange-0005.sql']],
+ ['exchange-0006.sql', ['exchange-0006.sql']],
+ ['exchange-0007.sql', ['exchange-0007.sql']],
+ ['exchange-0008.sql', ['exchange-0008.sql']],
+ ['exchange-0009.sql', exchange_0009_sql],
+ ['exchange-0010.sql', exchange_0010_sql],
+ ['tops-0001.sql', ['tops-0001.sql']],
+]
+
+foreach g : generated_sql
+ custom_target(
+ 'gen-exchangedb-' + g[0],
+ input: g[1],
+ output: g[0],
+ capture: true,
+ command: ['./amalgamate-sql.sh', '@INPUT@'],
+ install: true,
+ install_dir: sqldir,
+ )
endforeach
+
diff --git a/src/exchangedb/sql-schema/procedures-epilogue.sql b/src/exchangedb/sql-schema/procedures-epilogue.sql
@@ -0,0 +1,33 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2026 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/>
+--
+
+
+DROP PROCEDURE IF EXISTS exchange_do_gc;
+CREATE PROCEDURE exchange_do_gc(
+ IN in_ancient_date INT8,
+ IN in_now INT8)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CALL exchange_do_main_gc(in_ancient_date,in_now);
+ CALL exchange_statistic_amount_gc ();
+ CALL exchange_statistic_bucket_gc ();
+ CALL exchange_statistic_counter_gc ();
+END $$;
+COMMENT ON PROCEDURE exchange_do_gc
+ IS 'calls all other garbage collection subroutines';
+
+COMMIT;
diff --git a/src/exchangedb/sql-schema/procedures-preamble.sql b/src/exchangedb/sql-schema/procedures-preamble.sql
@@ -0,0 +1,19 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2025 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/>
+--
+
+BEGIN;
+
+SET search_path TO exchange;
diff --git a/src/exchangedb/sql-schema/procedures.sql.in b/src/exchangedb/sql-schema/procedures.sql.in
@@ -1,86 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2025 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/>
---
-
-BEGIN;
-
-SET search_path TO exchange;
-
-#include "exchange_do_create_partitioned_table.sql"
-#include "exchange_do_comment_partitioned_table.sql"
-#include "exchange_do_comment_partitioned_column.sql"
-#include "exchange_do_create_tables.sql"
-#include "exchange_do_amount_specific.sql"
-#include "../do_withdraw.sql"
-#include "../do_refresh.sql"
-#include "../do_deposit.sql"
-#include "../do_check_deposit_idempotent.sql"
--- dead!?
-#include "exchange_do_melt.sql"
-#include "../select_batch_deposits_missing_wire.sql"
--- dead!?
-#include "exchange_do_select_justification_for_missing_wire.sql"
-#include "../do_refund.sql"
-#include "../do_recoup.sql"
-#include "../do_recoup_refresh.sql"
-#include "../gc.sql"
-#include "../do_purse_delete.sql"
-#include "../do_purse_deposit.sql"
-#include "../do_purse_merge.sql"
-#include "../do_reserve_purse.sql"
-#include "../expire_purse.sql"
-#include "../insert_reserve_open_deposit.sql"
-#include "../do_reserve_open.sql"
-#include "../persist_policy_details.sql"
-#include "../insert_aml_decision.sql"
-#include "../insert_successor_measure.sql"
-#include "../insert_aml_officer.sql"
-#include "../reserves_in_insert.sql"
--- semi-dead...
-#include "exchange_do_get_link_data.sql"
-#include "../batch_ensure_coin_known.sql"
-#include "../kycauth_in_insert.sql"
-#include "../trigger_kyc_rule_for_account.sql"
-#include "../lookup_kyc_requirement_by_row.sql"
-#include "../insert_active_legitimization_measure.sql"
-#include "../select_aggregations_above_serial.sql"
-#include "../persist_kyc_attributes.sql"
-#include "../insert_aml_program_failure.sql"
-#include "../set_aml_lock.sql"
-#include "../insert_sanction_list_hit.sql"
-#include "exchange_statistics_helpers.sql"
-#include "exchange_trigger_purse_requests_insert.sql"
-#include "exchange_trigger_withdraw_delete.sql"
-#include "exchange_trigger_withdraw_insert.sql"
-#include "exchange_trigger_reserves_in_insert.sql"
-#include "exchange_trigger_purse_decision_insert.sql"
-#include "../get_kyc_rules.sql"
-
-DROP PROCEDURE IF EXISTS exchange_do_gc;
-CREATE PROCEDURE exchange_do_gc(
- IN in_ancient_date INT8,
- IN in_now INT8)
-LANGUAGE plpgsql
-AS $$
-BEGIN
- CALL exchange_do_main_gc(in_ancient_date,in_now);
- CALL exchange_statistic_amount_gc ();
- CALL exchange_statistic_bucket_gc ();
- CALL exchange_statistic_counter_gc ();
-END $$;
-COMMENT ON PROCEDURE exchange_do_gc
- IS 'calls all other garbage collection subroutines';
-
-COMMIT;