Sha256: cecfa155393b1b55265ca3548995d2bdab8442ae3ff98a505c87081808eca6dc

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

#!/usr/bin/env bash

set -e

echo
echo "Uninstalling Database"
echo "= = ="
echo

default_name=event_source

if [ -z ${DATABASE_USER+x} ]; then
  echo "(DATABASE_USER is not set. Default will be used.)"
  user=$default_name
else
  user=$DATABASE_USER
fi

if [ -z ${DATABASE_NAME+x} ]; then
  echo "(DATABASE_NAME is not set. Default will be used.)"
  database=$default_name
else
  database=$DATABASE_NAME
fi

echo

function delete-user {
  echo "Database user is: $user"

  user_exists=`psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$user'"`

  if [ "$user_exists" = "1" ]; then
    echo "Deleting database user \"$user\"..."
    dropuser $user
  else
    echo "Database user \"$user\" does not exist. Not deleting."
  fi

  echo
}

function delete-database {
  echo "Database name is: $database"

  database_exists=`psql -tAc "SELECT 1 FROM pg_database WHERE datname='$database'"`

  if [ "$database_exists" = "1" ]; then
    echo "Deleting database \"$database\"..."
    dropdb $database
  else
    echo "Database \"$database\" does not exist. Not deleting."
  fi

  echo
}


delete-database
delete-user

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
evt-event_source-postgres-0.19.0.1 database/uninstall.sh
evt-event_source-postgres-0.19.0.0 database/uninstall.sh