Skip to content

Commit e3f3d22

Browse files
committed
Merge pull request #7 from joncrlsn/release/0.9.1
Release/0.9.1 Former-commit-id: 5052ff7
2 parents 2cb4e89 + c1cb915 commit e3f3d22

28 files changed

+876
-173
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Jon Carlson
3+
Copyright (c) 2016 Jon Carlson
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,91 @@
11
# pgdiff - PostgreSQL schema diff
22

3-
An important feature of this utility is that it never modifies any database directly. You are solely responsible for verifying the generated SQL *before* running it against your database. Now that you know about that, it should give you confidence that it is safe to try out and see what SQL gets generated.
3+
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-
Written in GoLang, pgdiff compares the schema between two PostgreSQL databases and generates alter statements to be *manually* run against the second database. At the moment, not everything in the schema is compared, but the things considered important are: roles, sequences, tables, columns (and their default values), primary keys, unique constraints, foreign keys, roles, ownership information, and grants.
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-
It is written to be easy to add and 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-
[osx64](https://github.com/joncrlsn/pgrun/raw/master/bin-osx64/pgdiff "OSX 64-bit version")
11-
[osx32](https://github.com/joncrlsn/pgrun/raw/master/bin-osx32/pgdiff "OSX version")
12-
[linux64](https://github.com/joncrlsn/pgrun/raw/master/bin-linux64/pgdiff "Linux 64-bit version")
13-
[linux32](https://github.com/joncrlsn/pgrun/raw/master/bin-linux32/pgdiff "Linux version")
14-
[win64](https://github.com/joncrlsn/pgrun/raw/master/bin-win64/pgdiff.exe "Windows 64-bit version")
15-
[win32](https://github.com/joncrlsn/pgrun/raw/master/bin-win32/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")
1612

1713

1814
### usage
15+
pgdiff [options] <schemaType>
16+
17+
(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)
18+
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".
20+
21+
1. FUNCTION
22+
1. ROLE
23+
1. SEQUENCE
24+
1. TABLE
25+
1. COLUMN
26+
1. VIEW
27+
1. OWNER
28+
1. INDEX
29+
1. FOREIGN\_KEY
30+
1. GRANT\_RELATIONSHIP
31+
1. GRANT\_ATTRIBUTE
32+
1. TRIGGER
33+
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+
45+
### options
46+
47+
options | explanation
48+
----------------: | ------------------------------------
49+
-V, --version | prints the version of pgdiff being used
50+
-?, --help | displays helpful usage information
51+
-U, --user1 | first postgres user
52+
-u, --user2 | second postgres user
53+
-W, --password1 | first db password
54+
-w, --password2 | second db password
55+
-H, --host1 | first db host. default is localhost
56+
-h, --host2 | second db host. default is localhost
57+
-P, --port1 | first db port number. default is 5432
58+
-p, --port2 | second db port number. default is 5432
59+
-D, --dbname1 | first db name
60+
-d, --dbname2 | second db name
61+
-O, --option1 | first db options. example: sslmode=disable
62+
-o, --option2 | second db options. example: sslmode=disable
63+
64+
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
1980

20-
pgdiff [database flags] <schemaType>
2181

82+
### version history
83+
1. 0.9.0 - Implemented ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FOREIGN\_KEY, OWNER, GRANT\_RELATIONSHIP, GRANT\_ATTRIBUTE
84+
1. 0.9.1 - Added VIEW, FUNCTION, and TRIGGER (Thank you, Shawn Carroll AKA SparkeyG)
2285

23-
program flags | Explanation
24-
-------------: | ------------------------------------
25-
-U1 | first db postgres user
26-
-pw1 | first db password
27-
-h1 | first db host -- default is localhost
28-
-p1 | first db port number. defaults to 5432
29-
-d1 | first db name
30-
-U2 | second db postgres user
31-
-pw2 | second db password
32-
-h2 | second db host -- default is localhost
33-
-p2 | second db port number. defaults to 5432
34-
-d2 | second db name
3586

36-
&lt;schemaType&gt; the type of objects in the schema to compare: ALL, ROLE, SEQUENCE, TABLE, COLUMN, INDEX, FOREIGN_KEY, OWNER, GRANT_RELATIONSHIP, GRANT_ATTRIBUTE
87+
### todo
88+
1. fix SQL for adding an array column
89+
1. add windows version of pgdiff.sh (or even better: re-write it in Go)
90+
1. allow editing of individual SQL lines after failure (this would probably be done in the script pgdiff.sh)
91+
1. store failed SQL statements in an error file for later fixing and rerunning?

bin-linux/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Linux pgdiff instructions
2+
3+
These instructions will guide you through the process of generating SQL, reviewing it, and optionally running it on the target database. It requires a familiarity with a Linux command-line shell.
4+
5+
1. download pgdiff.tgz to your machine
6+
1. untar pgdiff.tgz (a new directory will be created: called pgdiff)
7+
1. cd into the new pgdiff directory
8+
1. optionally edit pgdiff.sh to change the db access values... or set them at runtime (i.e. USER1=joe NAME1=mydb USER2=joe NAME2=myotherdb ./pgdiff.sh)
9+
1. run pgdiff.sh
10+
11+
## tar contents
12+
* pgdiff - a linux executable
13+
* pgrun - a linux executable for running SQL
14+
* pgdiff.sh - a bash shell script to coordinate your interaction with pgdiff and pgrun
15+
16+
If you write a Go version of pgdiff.sh, please share it and I'll include it for others to use (with your copyright information intact).

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a43bac9815b274229ca929f86bedc43fdd4454a1

bin-linux32/pgdiff.REMOVED.git-id

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin-linux64/pgdiff.REMOVED.git-id

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin-osx/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## OSX / Mac pgdiff instructions
2+
3+
These instructions will guide you through the process of generating SQL, reviewing it, and optionally running it on the target database. It requires a familiarity with the bash shell in OSX.
4+
5+
1. download pgdiff.tgz to your machine
6+
1. untar pgdiff.tgz (a new directory will be created: called pgdiff)
7+
1. cd into the new pgdiff directory
8+
1. optionally edit pgdiff.sh to change the db access values... or set them at runtime (i.e. USER1=joe NAME1=mydb USER2=joe NAME2=myotherdb ./pgdiff.sh)
9+
1. run pgdiff.sh
10+
11+
## tar contents
12+
* pgdiff - an OSX executable
13+
* pgrun - an OSX executable for running SQL
14+
* pgdiff.sh - a bash shell script to coordinate your interaction with pgdiff and pgrun
15+
16+
If you write a Go version of pgdiff.sh, please share it and I'll include it for others to use (with your copyright information intact).

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7ed89cdc6de9635e5c3d39e341153dbc949d56a3

bin-osx32/pgdiff.REMOVED.git-id

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin-osx64/pgdiff.REMOVED.git-id

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)