Created
October 14, 2014 12:30
-
-
Save dimitrismistriotis/7872b6034b59356a6ed3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# | |
# Inspired from | |
# http://stackoverflow.com/questions/3327312/drop-all-tables-in-postgresql | |
# and modified for heroku CLI. | |
# | |
if [[ $# -ne 1 ]]; then | |
echo "Supply heroku app as first argument" >&2 | |
return 1 | |
fi | |
# | |
# tuples-only command line option is not supported for heroku pg:psql :-(. | |
# Prefixed with a '#' and then cut up to that. | |
# | |
RETRIEVE_TABLES_COMMAND="SELECT '#' || string_agg(table_name, ',') \ | |
FROM information_schema.tables \ | |
WHERE table_schema='public'" | |
TABLES=`heroku pg:psql --command $RETRIEVE_TABLES_COMMAND --app=$1 \ | |
| sed -n 's/[^#]*#//p'` | |
# echo "Retrieved: $TABLES" | |
for t ("${(s/,/)TABLES}"); do | |
echo "Dropping ${t}" | |
heroku pg:psql --command "DROP TABLE IF EXISTS ${t} CASCADE" --app=$1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Coderwall: https://coderwall.com/p/_n60nq