From fb1a621e3001436730aa0e5c8b2d3330289fd25d Mon Sep 17 00:00:00 2001 From: swrup Date: Tue, 10 Feb 2026 07:59:24 +0100 Subject: [PATCH] --- dbinit_sql/init.sql | 1 + process | 0 tools/dbinit.sh | 98 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 dbinit_sql/init.sql create mode 100644 process create mode 100755 tools/dbinit.sh diff --git a/dbinit_sql/init.sql b/dbinit_sql/init.sql new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/dbinit_sql/init.sql @@ -0,0 +1 @@ + diff --git a/process b/process new file mode 100644 index 00000000..e69de29b diff --git a/tools/dbinit.sh b/tools/dbinit.sh new file mode 100755 index 00000000..356b4d00 --- /dev/null +++ b/tools/dbinit.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# TODO +# - PostgreSQL configuration file/env variable +# (host, port, username, password, ..) + +# usage: +# `make create_database` +# create a `taler-exchange` database +# `make fetch_source` +# fetch all *.sql and *.sql.in files from GNU Taler exchange repository (latest commit) +# file `exchangedb.version` contains hash of latest commit that changed +# something in exchange/src/exchangedb +# `make init` +# initialize taler-exchange database (create tables, ...) +# `taler-exchange` database must already be created +# + + +set -e + +taler_repo_url="https://git-www.taler.net/exchange.git/" + +tmp_dir="/tmp/taler_exchange" +out_dir="./dbinit_sql" +out_init_sql="${out_dir}/init.sql" +out_init_drop="${out_dir}/drop.sql" + +dbname="taler-exchange" + +fetch() { + git clone --depth 1 $taler_repo_url $tmp_dir + #cp /tmp/exchange/src/exchangedb/*.sql $out_dir/ + #cp /tmp/exchange/src/exchangedb/*.sql.in $out_dir/ +} + +process() { + sql_in_files=( + "procedures.sql" + "exchange-0002.sql" + "exchange-0003.sql" + "exchange-0004.sql" + ) + for file in "$sql_in_files"; do + file="$tmp_dir/src/exchangedb/${file}.in" + # 2>/dev/null \ + gcc -E -P -undef $file \ + | sed -e "s/--.*//" \ + | awk 'NF' - \ + > $(out_dir)$1 + done + # order of files is important + sql_files=( + "versioning.sql" + "exchange-0001.sql" + "exchange-0002.sql" + "exchange-0003.sql" + "exchange-0004.sql" + "exchange-0005.sql" + "procedures.sql" ) + mkdir -p $out_dir + cat "${files[@]/#/${out_dir}/}" > $out_init_sql +} + +if [[ $# -eq 0 ]]; then + echo "no arguments" >&2 + exit 1 +fi + +cmd=$1 +case "$cmd" in + fetch) fetch "$@"; exit 0;; + process) process "$@"; exit 0;; + *) echo "Unknown command: $cmd" >&2; exit 1;; +esac + +#clean: +# rm -f procedures.sql +# rm -f exchange-0002.sql +# rm -f exchange-0003.sql +# rm -f exchange-0004.sql +# rm $(sql_INIT) +# +## "NOTICE: function xxx() does not exist, skipping" are normal and expected +#init: gen_init +# psql --host=localhost --port=5432 --username=mte --password --dbname=$(dbname) --file=$(sql_INIT) +# +#drop: +# psql --host=localhost --port=5432 --username=mte --password --dbname=$(dbname) --file=$(sql_DROP) +# +#create_database: +# createdb --host=localhost --port=5432 --username=mte --password $(dbname) +# +#drop_database: +# dropdb --host=localhost --port=5432 --username=mte --password $(dbname) +# +#reset_database: drop_database create_database +#