Skip to content

Commit

Permalink
bug fix for dbs that use a non-default port
Browse files Browse the repository at this point in the history
Former-commit-id: 4e30189
  • Loading branch information
joncrlsn committed Mar 2, 2016
1 parent c7f0177 commit d509502
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pgdiff is written to be easy to expand and improve the accuracy of the diff.

(where options and <schemaType> are listed below)

I've found that there is an ideal order for running the different schema types. This order should minimize the problems you encounter. For example, you'll always want to add new tables before you add new columns. This is the order that has worked for me, however "your mileage may vary".
I have found that there is an ideal order for running the different schema types. This order should minimize the problems you encounter. For example, you will always want to add new tables before you add new columns. This is the order that has worked for me, however "your mileage may vary".

Schema type ordering:

Expand All @@ -35,11 +35,11 @@ Schema type ordering:


### example
I have found it helpful to take ```--schema-only``` dumps of the databases in question, load them into a local postgres, then do my sql generation and testing there before running the SQL against a more official database. Your local postgres instance will need the correct users/roles populated because db dumps don't copy that information.
I have found it helpful to take ```--schema-only``` dumps of the databases in question, load them into a local postgres, then do my sql generation and testing there before running the SQL against a more official database. Your local postgres instance will need the correct users/roles populated because db dumps do not copy that information.

```
pgdiff -U dbuser -H localhost -D refDB -O 'sslmode=disable' \
-u dbuser -h localhost -d compDB -o 'sslmode=disable' \
pgdiff -U dbuser -H localhost -D refDB -O "sslmode=disable" \
-u dbuser -h localhost -d compDB -o "sslmode=disable" \
TABLE
```

Expand Down Expand Up @@ -87,6 +87,7 @@ linux and osx binaries are packaged with an extra, optional bash script and pgru
### version history
1. 0.9.0 - Implemented ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FOREIGN\_KEY, OWNER, GRANT\_RELATIONSHIP, GRANT\_ATTRIBUTE
1. 0.9.1 - Added VIEW, FUNCTION, and TRIGGER (Thank you, Shawn Carroll AKA SparkeyG)
1. 0.9.2 - Fixed bug when using the non-default port


### todo
Expand Down
2 changes: 1 addition & 1 deletion bin-linux/pgdiff.tgz.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a43bac9815b274229ca929f86bedc43fdd4454a1
600e71ce85d88c6926576979759796def05d473a
2 changes: 1 addition & 1 deletion bin-osx/pgdiff.tgz.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7ed89cdc6de9635e5c3d39e341153dbc949d56a3
b884f831690e5540a876c40ca4c0f1b2e4e871a9
2 changes: 1 addition & 1 deletion bin-win/pgdiff.exe.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d83feab2c337fca7826fb4a10152068b73c1e425
3d77712778ba60aa35e07e3c96a367dc6f66df7c
2 changes: 1 addition & 1 deletion pgdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Schema interface {
}

const (
version = "0.9.1"
version = "0.9.2"
)

var (
Expand Down
23 changes: 14 additions & 9 deletions pgdiff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
#
# If you convert this to a windows batch file (or, even better, a Go program), please share it.
#
# pgdiff -U postgres -W supersecret -D maindb -O sslmode=disable -u postgres -w supersecret -d stagingdb -o sslmode=disable COLUMN
# Example:
# pgdiff -U postgres -W supersecret -H dbhost1 -P 5432 -D maindb -O 'sslmode=disable' \
# -u postgres -w supersecret -h dbhost2 -p 5432 -d stagingdb -o 'sslmode=disable' \
# COLUMN
#

[[ -z $USER1 ]] && USER1=admin
[[ -z $HOST1 ]] && HOST1=localhost
[[ -z $NAME1 ]] && NAME1=prd-db
[[ -z $PORT1 ]] && PORT1=5432
[[ -z $NAME1 ]] && NAME1=main-db
[[ -z $OPT1 ]] && OPT1='sslmode=disable'

[[ -z $USER2 ]] && USER2=admin
[[ -z $HOST2 ]] && HOST2=localhost
[[ -z $NAME2 ]] && NAME2=qa-db
[[ -z $PORT2 ]] && PORT2=5432
[[ -z $NAME2 ]] && NAME2=stg-db
[[ -z $OPT2 ]] && OPT2='sslmode=disable'

echo "This is the reference database:"
echo " ${USER1}@${HOST1}/$NAME1"
echo " ${USER1}@${HOST1}:${PORT1}/$NAME1"
read -sp "Enter DB password: " passw
PASS1=$passw
PASS2=$passw

echo
echo "This database may be changed (if you choose):"
echo " ${USER2}@${HOST2}/$NAME2"
echo " ${USER2}@${HOST2}:${PORT2}/$NAME2"
read -sp "Enter DB password (defaults to previous password): " passw
[[ -n $passw ]] && PASS2=$passw
echo
Expand All @@ -37,15 +42,15 @@ function rundiff() {
local TYPE=$1
local sqlFile="${i}-${TYPE}.sql"
echo "Generating diff for $TYPE... "
./pgdiff -U "$USER1" -W "$PASS1" -H "$HOST1" -D "$NAME1" -O "$OPT1" \
-u "$USER2" -w "$PASS2" -h "$HOST2" -d "$NAME2" -o "$OPT2" \
$TYPE > "$sqlFile"
./pgdiff -U "$USER1" -W "$PASS1" -H "$HOST1" -P "$PORT1" -D "$NAME1" -O "$OPT1" \
-u "$USER2" -w "$PASS2" -h "$HOST2" -p "$PORT2" -d "$NAME2" -o "$OPT2" \
$TYPE > "$sqlFile"
RC=$? && [[ $RC != 0 ]] && exit $RC
echo -n "Press Enter to review the generated output: "; read x
vi "$sqlFile"
echo -n "Do you wish to run this against ${NAME2}? [yN]: "; read x
if [[ $x =~ ^y ]]; then
PGPASSWORD="$PASS2" ./pgrun -U $USER2 -h $HOST2 -d $NAME2 -O "$OPT2" -f "$sqlFile"
PGPASSWORD="$PASS2" ./pgrun -U $USER2 -h $HOST2 -p $PORT2 -d $NAME2 -O "$OPT2" -f "$sqlFile"
fi
echo
}
Expand Down

0 comments on commit d509502

Please sign in to comment.