dbinit.sh: use git tag
This commit is contained in:
parent
1c7a67aa80
commit
42b7e13eae
2 changed files with 40 additions and 30 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
_build
|
||||
_taler_exchange_sql
|
||||
_dbinit_sql
|
||||
vendors
|
||||
assets
|
||||
secmod.fat
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue