This commit is contained in:
swrup 2026-02-10 07:59:24 +01:00
parent cbfcbdd046
commit a6a1e1af05
3 changed files with 100 additions and 0 deletions

100
tools/dbinit.sh Executable file
View file

@ -0,0 +1,100 @@
#!/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}/${file}"
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
for file in "$sql_files"; do
cat "${out_dir}/${file}" > $out_init_sql
done
}
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
#