diff scripts/.functions.sh @ 73:d2c44193fbaa

explictly remove db's before import
author smith@nwoca.org
date Mon, 21 Mar 2016 22:17:55 +0100
parents scripts/info.sh@1988f9924439
children 85957628f4c0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/.functions.sh	Mon Mar 21 22:17:55 2016 +0100
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# deletes psql data from specified service
+resetDbVolume() {
+#   Works for named and unnamed volumes and custom $PGDATA.
+#   Container must be stopped
+   service=${1?Must supply db service to reset}
+   container=$(composeGetContainer $service)
+   if [ "$container" != "" ]
+   then
+      echo "deleting db data from $container"
+      docker-compose run --no-deps --rm $service bash -c "rm -rf \${PGDATA?Missing PGDATA env}"
+   fi
+}
+
+# finds docker container for specified compose service 
+composeGetContainer() {
+  service=${1?"Must supply service from current project"}
+
+  container=$( docker-compose ps | cut -d " " -f 1 -s | grep _${service}_ )
+  echo $container
+}