changeset 73:d2c44193fbaa

explictly remove db's before import
author smith@nwoca.org
date Mon, 21 Mar 2016 22:17:55 +0100
parents 6f562946db80
children 541766977a11
files scripts/.functions.sh scripts/capture.sh scripts/import-usas.sh scripts/import-usps.sh
diffstat 4 files changed, 29 insertions(+), 2 deletions(-) [+]
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
+}
--- a/scripts/capture.sh	Fri Mar 18 01:45:42 2016 +0100
+++ b/scripts/capture.sh	Mon Mar 21 22:17:55 2016 +0100
@@ -1,3 +1,3 @@
 #!/bin/bash
 # writes tail of current logs to standard out from running containers in compose project.
-docker-compose ps -q | xargs -I ID docker inspect --format='{{.LogPath}}' ID | xargs tail -n8000
+docker-compose ps -q | xargs -I ID docker inspect --format='{{.LogPath}}' ID | xargs tail -n${1-8000}
--- a/scripts/import-usas.sh	Fri Mar 18 01:45:42 2016 +0100
+++ b/scripts/import-usas.sh	Mon Mar 21 22:17:55 2016 +0100
@@ -1,6 +1,9 @@
 #!/bin/bash
 
+source "$( dirname "${BASH_SOURCE[0]}")/.functions.sh"
+
 docker-compose stop usasapp usasdb
+resetDbVolume usasdb
 docker-compose rm -vf usasapp usasdb
 
 export IMP_IRN=${IMP_IRN}
--- a/scripts/import-usps.sh	Fri Mar 18 01:45:42 2016 +0100
+++ b/scripts/import-usps.sh	Mon Mar 21 22:17:55 2016 +0100
@@ -1,6 +1,9 @@
 #!/bin/bash
 
+source "$( dirname "${BASH_SOURCE[0]}")/.functions.sh"
+
 docker-compose stop uspsapp uspsdb
+resetDbVolume uspsdb
 docker-compose rm -vf uspsapp uspsdb
 
 export IMP_IRN=${IMP_IRN}
@@ -16,4 +19,3 @@
 docker-compose -f docker-compose.yml -f /ssdt/compose/preview/import.yml rm -f uspsimport
 # start application
 docker-compose up -d uspsapp
-