Skip to content
Snippets Groups Projects
Commit efa1f647 authored by Bartek Wrona's avatar Bartek Wrona Committed by Dan Notestein
Browse files

Defined drop_db.sh script to clean all Hivemind specific data created in HAF database.

parent bcff7c67
No related branches found
No related tags found
2 merge requests!827Merge develop changes to master,!617Defined drop_db.sh script to clean all Hivemind specific data created in HAF database.
#! /bin/sh
set -e
print_help () {
cat <<EOF
Usage: $0 [OPTION[=VALUE]]...
Allows to setup a database already filled by HAF instance, to work with Hivemind application.
OPTIONS:
--host=VALUE Allows to specify a PostgreSQL host location (defaults to localhost)
--port=NUMBER Allows to specify a PostgreSQL operating port (defaults to 5432)
--user=VALUE Allows to specify a PostgreSQL user (defaults to haf_admin)
--url=URL Allows to specify a PostgreSQL URL (empty by default, overrides options above)
--help,-h,-? Displays this help message
EOF
}
POSTGRES_USER=${POSTGRES_USER:-"haf_admin"}
POSTGRES_HOST=${POSTGRES_HOST:-"localhost"}
POSTGRES_PORT=${POSTGRES_PORT:-5432}
POSTGRES_URL=${POSTGRES_URL:-""}
while [ $# -gt 0 ]; do
case "$1" in
--host=*)
POSTGRES_HOST="${1#*=}"
;;
--port=*)
POSTGRES_PORT="${1#*=}"
;;
--user=*)
POSTGRES_USER="${1#*=}"
;;
--postgres-url=*)
POSTGRES_URL="${1#*=}"
;;
--help|-h|-?)
print_help
exit 0
;;
-*)
echo "ERROR: '$1' is not a valid option"
echo
print_help
exit 1
;;
*)
echo "ERROR: '$1' is not a valid argument"
echo
print_help
exit 2
;;
esac
shift
done
POSTGRES_ACCESS_ADMIN=${POSTGRES_URL:-"postgresql://$POSTGRES_USER@$POSTGRES_HOST:$POSTGRES_PORT/haf_block_log"}
drop_db() {
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=ON" -c "do \$\$ BEGIN if hive.app_context_exists('hivemind_app') THEN perform hive.app_remove_context('hivemind_app'); end if; END \$\$"
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=ON" -c "DROP SCHEMA IF EXISTS hivemind_app CASCADE;"
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=ON" -c "REASSIGN OWNED BY hivemind TO postgres; "
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=ON" -c "DROP OWNED BY hivemind"
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=ON" -c "DROP ROLE hivemind"
}
drop_db
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment