Skip to content

Commit 8f54010

Browse files
committed
Final 0.9.1 commit
Former-commit-id: 54e0c74
1 parent 3b41c02 commit 8f54010

7 files changed

Lines changed: 52 additions & 17 deletions

File tree

README.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,46 @@
22

33
pgdiff compares the schema between two PostgreSQL 9 databases and generates alter statements to be *manually* run against the second database to make them match. The provided pgdiff.sh script helps automate the process.
44

5-
pgdiff is transparent in what it does, so it never modifies a database directly. You alone are responsible for verifying the generated SQL *before* running it against your database, so you can have confidence that pgdiff is safe to try and see what SQL gets generated.
5+
pgdiff is transparent in what it does, so it never modifies a database directly. You alone are responsible for verifying the generated SQL before running it against your database. Go ahead and see what SQL gets generated.
6+
7+
pgdiff is written to be easy to expand and improve the accuracy of the diff.
68

7-
pgdiff is written to be easy to improve the accuracy of the diff. If you find something that seems wrong and you want me to look at it, please send me two schema-only database dumps that I can test with (Use the --schema-only option with pg\_dump)
89

910
### download
10-
[osx](https://github.com/joncrlsn/pgrun/raw/master/bin-osx/pgdiff "OSX version")
11-
[linux](https://github.com/joncrlsn/pgrun/raw/master/bin-linux/pgdiff "Linux version")
12-
[windows](https://github.com/joncrlsn/pgrun/raw/master/bin-win/pgdiff.exe "Windows version")
11+
[osx](https://github.com/joncrlsn/pgrun/raw/master/bin-osx/pgdiff "OSX version")   [linux](https://github.com/joncrlsn/pgrun/raw/master/bin-linux/pgdiff "Linux version")   [windows](https://github.com/joncrlsn/pgrun/raw/master/bin-win/pgdiff.exe "Windows version")
12+
1313

1414
### usage
15-
pgdiff [options] <schemaType>
15+
pgdiff [options] <schemaType>
1616

1717
(where options are defined below and &lt;schemaType&gt; can be: ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FUNCTION, VIEW, FOREIGN\_KEY, OWNER, GRANT\_RELATIONSHIP, GRANT\_ATTRIBUTE, TRIGGER)
1818

19-
I've found that there is an ideal order for running the different schema types. 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".
19+
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".
2020

2121
1. FUNCTION
2222
1. ROLE
2323
1. SEQUENCE
2424
1. TABLE
25+
1. COLUMN
2526
1. VIEW
2627
1. OWNER
27-
1. COLUMN
2828
1. INDEX
2929
1. FOREIGN\_KEY
3030
1. GRANT\_RELATIONSHIP
3131
1. GRANT\_ATTRIBUTE
3232
1. TRIGGER
3333

34+
35+
### example
36+
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.
37+
38+
```
39+
pgdiff -U dbuser -H localhost -D refDB -O 'sslmode=disable' \
40+
-u dbuser -h localhost -d compDB -o 'sslmode=disable' \
41+
TABLE
42+
```
43+
44+
3445
### options
3546

3647
options | explanation
@@ -51,12 +62,30 @@ options | explanation
5162
-o, --option2 | second db options. example: sslmode=disable
5263

5364

65+
### getting started on linux and osx
66+
linux and osx binaries are packaged with an extra, optional bash script and pgrun program that helps speed the diffing process.
67+
1. download the tgz file for your OS
68+
1. untar it: ```tar -xzvf pgdiff.tgz```
69+
1. cd to the new pgdiff directory
70+
1. edit the db connection defaults in pgdiff.sh
71+
1. ...or manually run pgdiff for each schema type listed in the usage section above
72+
1. review the SQL output for each schema type and, if you want to make them match, run it against db2
73+
74+
75+
### getting started on windows
76+
1. download pgdiff.exe from the bin-win directory on github
77+
1. edit the db connection defaults in pgdiff.sh or...
78+
1. manually run pgdiff for each schema type listed in the usage section above
79+
1. review the SQL output and, if you want to make them match, run it against db2
80+
81+
5482
### version history
5583
1. 0.9.0 - Implemented ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FOREIGN\_KEY, OWNER, GRANT\_RELATIONSHIP, GRANT\_ATTRIBUTE
5684
1. 0.9.1 - Added VIEW, FUNCTION, and TRIGGER (Thank you, Shawn Carroll AKA SparkeyG)
5785

86+
5887
### todo
5988
1. fix SQL for adding an array column
6089
1. add windows version of pgdiff.sh (or even better: re-write it in Go)
61-
1. allow editing of individual SQL lines after failure (this would be done in the script pgdiff.sh)
90+
1. allow editing of individual SQL lines after failure (this would probably be done in the script pgdiff.sh)
6291
1. store failed SQL statements in an error file for later fixing and rerunning?
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b33644e000965e421a9c120a899ac60ad17eab46
1+
bc4346731208e5b88b3fbbbaf027dfc557471e8c

bin-osx/pgdiff.tgz.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b9845f185d9d08d675362c1e59d30a1eb077cbb6
1+
cb71ed6dbe48377ffce0cd089954f7014d23aaf1

bin-win/pgdiff.exe.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ca1230a10b8dcd2278742126b62acbaf0d153201
1+
d83feab2c337fca7826fb4a10152068b73c1e425

build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash -x
2+
#
3+
# For OSX and Linux, this script:
4+
# * builds pgdiff
5+
# * downloads pgrun
6+
# * combines them and pgdiff.sh into a tgz file
7+
#
28

39
SCRIPT_DIR="$(dirname `ls -l $0 | awk '{ print $NF }'`)"
410

@@ -45,7 +51,7 @@ if [[ -d bin-osx ]]; then
4551
COPYFILE_DISABLE=true tar -cvzf "${APPNAME}.tgz" $APPNAME
4652
cd -
4753
mv "${tempdir}/${APPNAME}.tgz" "${SCRIPT_DIR}/bin-osx/"
48-
echo "Built osx32."
54+
echo "Built osx."
4955
else
5056
echo "Skipping osx. No bin-osx directory."
5157
fi

index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ JOIN pg_catalog.pg_class AS c ON (c.oid = i.indrelid)
227227
JOIN pg_catalog.pg_class AS c2 ON (c2.oid = i.indexrelid)
228228
LEFT JOIN pg_catalog.pg_constraint con
229229
ON (con.conrelid = i.indrelid AND con.conindid = i.indexrelid AND con.contype IN ('p','u','x'))
230+
JOIN pg_catalog.pg_namespace AS n ON (c2.relnamespace = n.oid)
230231
WHERE c.relname NOT LIKE 'pg_%'
231-
--AND c.relname = 't_org'
232-
--ORDER BY c.relname, c2.relname;
232+
AND n.nspname = 'public';
233233
`
234234
rowChan1, _ := pgutil.QueryStrings(conn1, sql)
235235
rowChan2, _ := pgutil.QueryStrings(conn2, sql)

pgdiff.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function rundiff() {
4545
vi "$sqlFile"
4646
echo -n "Do you wish to run this against ${NAME2}? [yN]: "; read x
4747
if [[ $x =~ ^y ]]; then
48-
PGPASSWORD="$PASS2" pgrun -U $USER2 -h $HOST2 -d $NAME2 -O "$OPT2" -f "$sqlFile"
48+
PGPASSWORD="$PASS2" ./pgrun -U $USER2 -h $HOST2 -d $NAME2 -O "$OPT2" -f "$sqlFile"
4949
fi
5050
echo
5151
}
@@ -54,9 +54,9 @@ rundiff FUNCTION
5454
rundiff ROLE
5555
rundiff SEQUENCE
5656
rundiff TABLE
57+
rundiff COLUMN
5758
rundiff VIEW
5859
rundiff OWNER
59-
rundiff COLUMN
6060
rundiff INDEX
6161
rundiff FOREIGN_KEY
6262
rundiff GRANT_RELATIONSHIP

0 commit comments

Comments
 (0)