This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convenience db_reset script (#45)
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
# Provide me with a postgres database name, and I will: | ||
# - Drop the database | ||
# - Recreate the database | ||
# - Run the vulcanizedb migration | ||
|
||
if [ "$1" = "" ]; then | ||
echo "Provide a database name to reset" | ||
exit 1 | ||
fi | ||
|
||
db=$1 | ||
dir=$(basename "$(pwd)") | ||
if [ $dir != "vulcanizedb" ] | ||
then | ||
echo "Run me from the vulcanizedb root dir" | ||
exit 1 | ||
fi | ||
|
||
user=$(whoami) | ||
psql -c "DROP DATABASE $db" postgres | ||
if [ $? -eq 0 ]; then | ||
psql -c "CREATE DATABASE $db WITH OWNER $user" postgres | ||
make migrate HOST_NAME=localhost NAME=$db PORT=5432 | ||
else | ||
echo "Couldnt drop the database. Are you connected? Does it exist?" | ||
fi |