From 42b7e13eae02e299d20f84497ce06925c9bc3c87 Mon Sep 17 00:00:00 2001 From: swrup Date: Tue, 12 May 2026 02:23:46 +0200 Subject: [PATCH] dbinit.sh: use git tag --- .gitignore | 2 +- tools/dbinit.sh | 68 ++++++++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index b7e9aaa8..3adc2256 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ _build -_taler_exchange_sql +_dbinit_sql vendors assets secmod.fat diff --git a/tools/dbinit.sh b/tools/dbinit.sh index 726dafad..258bd770 100755 --- a/tools/dbinit.sh +++ b/tools/dbinit.sh @@ -1,25 +1,36 @@ -#!/bin/bash +#!/bin/sh -# TODO -# use specific commit - -# usage: -# `create_database` -# create a `taler-exchange` database -# `fetch` -# fetch all *.sql and *.sql.in files from GNU Taler exchange repository (latest commit) -# `init` -# initialize taler-exchange database (create tables, ...) -# `taler-exchange` database must already be created +# Script to initialize a taler-exchange database. +# To use as an alternative to the taler-exchange-dbinit tool. # +# This script aggregate GNU Taler exchange's SQL files together, +# and send commands to PostgreSQL server with `psql`. +# Usage: +# `fetch` +# fetch all *.sql and *.sql.in files from GNU Taler exchange repository +# `build` +# merge *.sql and *.sql.in files to produce `init.sql` and `drop.sql` +# `database_init` +# create a `taler-exchange` database +# `database_drop` +# drop `taler-exchange` database +# `init` +# apply `init.sql` +# (database must already be created) +# `drop` +# apply `drop.sql` + set -e taler_repo_url="https://git-www.taler.net/exchange.git/" +# todo +# update to use taler exchange new build system and better *.sql organization +taler_repo_tag="v1.5.0" tmp_dir="/tmp/taler_exchange" -out_dir="./_taler_exchange_sql" +out_dir="./_dbinit_sql" init_sql="${out_dir}/init.sql" drop_sql="${out_dir}/drop.sql" @@ -30,10 +41,10 @@ username="mte" dbname="taler-exchange" fetch() { - git clone --depth 1 $taler_repo_url $tmp_dir + git clone --depth 1 --branch $taler_repo_tag $taler_repo_url $tmp_dir } -process() { +build() { source_dir="${tmp_dir}/src/exchangedb" sql_in_files=( "procedures.sql" @@ -66,23 +77,22 @@ process() { done } -# ? "NOTICE: function xxx() does not exist, skipping" +database_init() { + createdb --host=$host --port=$port --username=$username --password $dbname +} + +database_drop() { + dropdb --host=$host --port=$port --username=$username --password $dbname +} + init() { psql --host=$host --port=$port --username=$username --password --dbname=$dbname --file=$init_sql } -drop_schema() { +drop() { psql --host=$host --port=$port --username=$username --password --dbname=$dbname --file=$drop_sql } -create_database() { - createdb --host=$host --port=$port --username=$username --password $dbname -} - -drop_database() { - dropdb --host=$host --port=$port --username=$username --password $dbname -} - if [[ $# -eq 0 ]]; then echo "no argument" >&2 exit 1 @@ -91,10 +101,10 @@ fi cmd=$1 case "$cmd" in fetch) fetch "$@"; exit 0;; - process) process "$@"; exit 0;; + build) build "$@"; exit 0;; + database_init) database_init "$@"; exit 0;; + database_drop) database_drop "$@"; exit 0;; init) init "$@"; exit 0;; - drop_schema) drop_schema "$@"; exit 0;; - create_database) create_database "$@"; exit 0;; - drop_database) drop_database "$@"; exit 0;; + drop) drop "$@"; exit 0;; *) echo "Unknown command: $cmd" >&2; exit 1;; esac