pg_examiner 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -2
- data/TODO.txt +0 -13
- data/lib/pg_examiner.rb +8 -2
- data/lib/pg_examiner/result.rb +7 -3
- data/lib/pg_examiner/result/schema.rb +1 -1
- data/lib/pg_examiner/version.rb +1 -1
- data/spec/schema_spec.rb +20 -0
- data/spec/spec_helper.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d356dc864a178282a0215872ebada1d1632bde1f
|
4
|
+
data.tar.gz: dd10dd54b238c784dd2a64860fc4ea2bb603fd9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86f551bd4b3f744071d176bc78bfe0b8a67468dacbed61af64fb10ec822f1ecd24357d960b609dd1936852e87f64802ef3da0c7c95573924260e12d1d96b7c6f
|
7
|
+
data.tar.gz: 027020de63882cdc3040dc84e7f48426503a0f6ca36a7071dd7322453087dce450d6f0eefe722ef838c289ee3bbfb4b885ec7b17870b50fc6d680e23f73f95ad
|
data/README.md
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
# PGExaminer
|
2
2
|
|
3
|
-
|
3
|
+
A tool for comparing PG database structures. Use it to ensure that downward migrations precisely undo upward ones, or that different sets of migrations produce the same schema, or that different schemas in a multitenanted database all have the same structure.
|
4
|
+
|
5
|
+
PGExaminer tries to be sensible about equivalency. For example, it will understand that two tables are equivalent if they have the same name, column names, column types, triggers, constraints, and indices. It won't care about the contents of the tables. It will care about the order the columns are in, but will ignore columns that have been dropped.
|
6
|
+
|
7
|
+
PGExaminer is NOT exhaustive. It currently doesn't have tests for its understanding of:
|
8
|
+
|
9
|
+
1. Aggregate functions
|
10
|
+
2. Column TOAST settings
|
11
|
+
3. Sequences
|
12
|
+
4. Views
|
13
|
+
5. User-defined types or enums
|
14
|
+
6. Object COMMENTs
|
15
|
+
7. Materialized views
|
16
|
+
8. Constraint deferral states
|
17
|
+
9. Exclusion constraints
|
18
|
+
10. Inheritance structures
|
19
|
+
11. User-defined objects in the system (pg_*) schemas or information_schema.
|
20
|
+
12. ...Probably some other stuff.
|
21
|
+
|
22
|
+
It may or may not understand these objects. If you're using one of these, or another Postgres feature that may be considered obscure, please test it out first. I'll be happy to add support for more objects if there's demand.
|
4
23
|
|
5
24
|
## Installation
|
6
25
|
|
@@ -18,7 +37,20 @@ Or install it yourself as:
|
|
18
37
|
|
19
38
|
## Usage
|
20
39
|
|
21
|
-
|
40
|
+
``` ruby
|
41
|
+
# Need a PG::Connection object. See your ORM's documentation for how to get one.
|
42
|
+
|
43
|
+
# To make sure migrations work right:
|
44
|
+
state1 = PGExaminer.examine(connection)
|
45
|
+
# Migrate up then down.
|
46
|
+
state2 = PGExaminer.examine(connection)
|
47
|
+
state1 == state2 # => true or false
|
48
|
+
|
49
|
+
# To make sure schema1 and schema2 have the same contents:
|
50
|
+
state1 = PGExaminer.examine(connection, :schema1)
|
51
|
+
state2 = PGExaminer.examine(connection, :schema2)
|
52
|
+
state1 == state2 # => true or false
|
53
|
+
```
|
22
54
|
|
23
55
|
## Contributing
|
24
56
|
|
data/TODO.txt
CHANGED
@@ -65,21 +65,11 @@ inhrelid
|
|
65
65
|
inhparent
|
66
66
|
inhseqno
|
67
67
|
|
68
|
-
pg_language (http://www.postgresql.org/docs/9.3/static/catalog-pg-language.html)
|
69
|
-
lanname
|
70
|
-
|
71
68
|
pg_proc (http://www.postgresql.org/docs/9.3/static/catalog-pg-proc.html)
|
72
|
-
proname
|
73
|
-
pronamespace
|
74
|
-
procost
|
75
|
-
prorows?
|
76
|
-
provariadic
|
77
69
|
proisagg
|
78
70
|
proiswindow
|
79
71
|
proleakproof?
|
80
|
-
proisstrict
|
81
72
|
proretset
|
82
|
-
provolatile
|
83
73
|
pronargs
|
84
74
|
pronargdefaults
|
85
75
|
prorettype
|
@@ -90,9 +80,6 @@ proargnames
|
|
90
80
|
nodeToString(proargdefaults)
|
91
81
|
|
92
82
|
pg_trigger (http://www.postgresql.org/docs/9.3/static/catalog-pg-trigger.html)
|
93
|
-
tgrelid
|
94
|
-
tgname
|
95
|
-
tgfoid
|
96
83
|
tgtype
|
97
84
|
tgisinternal
|
98
85
|
tgconstrrelid
|
data/lib/pg_examiner.rb
CHANGED
@@ -3,8 +3,14 @@ require 'pg_examiner/version'
|
|
3
3
|
|
4
4
|
module PGExaminer
|
5
5
|
class << self
|
6
|
-
def examine(connection)
|
7
|
-
Result.new(connection)
|
6
|
+
def examine(connection, schema = nil)
|
7
|
+
result = Result.new(connection)
|
8
|
+
|
9
|
+
if schema
|
10
|
+
result.schemas.find { |s| s.name == schema.to_s }
|
11
|
+
else
|
12
|
+
result
|
13
|
+
end
|
8
14
|
end
|
9
15
|
end
|
10
16
|
end
|
data/lib/pg_examiner/result.rb
CHANGED
@@ -41,10 +41,14 @@ module PGExaminer
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def ==(other)
|
44
|
+
# We want to be able to compare the contents of two schemas to each
|
45
|
+
# other, so compare names at the top level instead of schema-to-schema.
|
46
|
+
|
44
47
|
other.is_a?(Result) &&
|
45
|
-
schemas
|
46
|
-
|
47
|
-
|
48
|
+
schemas.map(&:name) == other.schemas.map(&:name) &&
|
49
|
+
schemas == other.schemas &&
|
50
|
+
extensions == other.extensions &&
|
51
|
+
languages == other.languages
|
48
52
|
end
|
49
53
|
|
50
54
|
def inspect
|
data/lib/pg_examiner/version.rb
CHANGED
data/spec/schema_spec.rb
CHANGED
@@ -20,4 +20,24 @@ describe PGExaminer do
|
|
20
20
|
result.schemas.length.should == 2
|
21
21
|
result.schemas.map(&:name).should == %w(my_schema public)
|
22
22
|
end
|
23
|
+
|
24
|
+
it "should be able to compare the contents of different schemas" do
|
25
|
+
a = examine <<-SQL, :schema1
|
26
|
+
CREATE SCHEMA schema1;
|
27
|
+
CREATE TABLE schema1.test_table (
|
28
|
+
a integer,
|
29
|
+
b integer
|
30
|
+
);
|
31
|
+
SQL
|
32
|
+
|
33
|
+
b = examine <<-SQL, :schema2
|
34
|
+
CREATE SCHEMA schema2;
|
35
|
+
CREATE TABLE schema2.test_table (
|
36
|
+
a integer,
|
37
|
+
b integer
|
38
|
+
);
|
39
|
+
SQL
|
40
|
+
|
41
|
+
a.should == b
|
42
|
+
end
|
23
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,10 +11,10 @@ CONNECTION = PG::Connection.open :host => uri.host,
|
|
11
11
|
:dbname => uri.path[1..-1]
|
12
12
|
|
13
13
|
RSpec.configure do |config|
|
14
|
-
def examine(sql)
|
14
|
+
def examine(sql, schema = nil)
|
15
15
|
execute "BEGIN"
|
16
16
|
execute(sql)
|
17
|
-
PGExaminer.examine(CONNECTION)
|
17
|
+
PGExaminer.examine(CONNECTION, schema)
|
18
18
|
ensure
|
19
19
|
execute "ROLLBACK"
|
20
20
|
end
|