make db scripts accept one db at a time

This commit is contained in:
Min RK
2017-09-28 13:28:17 +02:00
parent f733a91d7c
commit 4534499aad
2 changed files with 44 additions and 25 deletions

View File

@@ -1,14 +1,27 @@
#!/usr/bin/env bash
# initialize jupyterhub databases for testing
set -e
MYSQL="mysql --user root -e "
PSQL="psql --user postgres -c "
case "$DB" in
"mysql")
EXTRA_CREATE='CHARACTER SET utf8 COLLATE utf8_general_ci'
SQL="$MYSQL"
;;
"postgres")
SQL="$PSQL"
;;
*)
echo '$DB must be mysql or postgres'
exit 1
esac
set -x
# drop databases if they don't exist
$MYSQL 'DROP DATABASE jupyterhub_upgrade' 2>/dev/null || true
$PSQL 'DROP DATABASE jupyterhub_upgrade' 2>/dev/null || true
# create the databases
$MYSQL 'CREATE DATABASE jupyterhub_upgrade CHARACTER SET utf8 COLLATE utf8_general_ci;'
$PSQL 'CREATE DATABASE jupyterhub_upgrade;'
$SQL 'DROP DATABASE jupyterhub;' 2>/dev/null || true
$SQL "CREATE DATABASE jupyterhub ${EXTRA_CREATE};"
$SQL 'DROP DATABASE jupyterhub_upgrade;' 2>/dev/null || true
$SQL "CREATE DATABASE jupyterhub_upgrade ${EXTRA_CREATE};"