pg_examiner 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36c51dbbc8e2fccfd5eee408216749e98c20086d
4
- data.tar.gz: 373bfeb979ed1012d4a05daf1dd5d4720b8c8a65
3
+ metadata.gz: 697245ba4c753820e5ebb80a41c5776db2b5251b
4
+ data.tar.gz: d363b5efac3c568c25bf2976185674c9a0473023
5
5
  SHA512:
6
- metadata.gz: 982b849a8951bf7f9b783cf6ccb9e29d78d55c52a8d0158ec0f15dd474a1986a43a2b88931e0aff1a80915cb7683d82fd1e71b09c192374bb38c8a4650d5aa9c
7
- data.tar.gz: 79cb8766ad4867ea4170dc6e5445ed86f849bba61e900982800a4a4355aa600fae7779f7c7176190fa3481375b649db028d4a175b1b79eb81cd466cbdb3dba0b
6
+ metadata.gz: fd7e6790209d5af475aa27d2f4309b2da294fb33e0ba58f09de18c610a2b7559e7bc1527a72b403a6e5586fb891c298cf751af727772f065dcd099fe09a6b61d
7
+ data.tar.gz: 0b4520614f4f8eeb35b12ce5810ca8a996989d29e2f41531c32a80666c9e402082f7190f8f5bf8af158f17b87fe5a8dfee1af6f862b47c6593d9ab0ec5ddfa6e
@@ -29,7 +29,7 @@ module PGExaminer
29
29
  @default
30
30
  else
31
31
  @default_calculated = true
32
- @default = result.pg_attrdef.find{|d| d['adrelid'] == row['attrelid']}['default'] if row['atthasdef'] == 't'
32
+ @default = result.pg_attrdef.find{|d| d['adrelid'] == row['attrelid'] && d['adnum'] == row['attnum']}['default'] if row['atthasdef'] == 't'
33
33
  end
34
34
  end
35
35
  end
@@ -106,7 +106,7 @@ module PGExaminer
106
106
  SQL
107
107
 
108
108
  @pg_attrdef = execute <<-SQL
109
- SELECT oid, adrelid, pg_get_expr(adbin, adrelid) AS default
109
+ SELECT oid, adrelid, adnum, pg_get_expr(adbin, adrelid) AS default
110
110
  FROM pg_attrdef
111
111
  SQL
112
112
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PGExaminer
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -6,13 +6,13 @@ describe PGExaminer do
6
6
  it "should be able to examine the extensions in the db" do
7
7
  result1 = examine "SELECT 1"
8
8
  result1.should be_an_instance_of PGExaminer::Result
9
- result1.extensions.map(&:name).should == ['plpgsql']
9
+ result1.extensions.map(&:name).should == ['plpgsql', 'uuid-ossp']
10
10
 
11
11
  result2 = examine <<-SQL
12
12
  CREATE EXTENSION citext;
13
13
  SQL
14
14
 
15
- result2.extensions.length.should == 2
15
+ result2.extensions.length.should == 3
16
16
 
17
17
  citext, plpgsql = result2.extensions # Ordered by name
18
18
 
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,9 @@ CONNECTION = PG::Connection.open :host => uri.host,
12
12
  :port => uri.port || 5432,
13
13
  :dbname => uri.path[1..-1]
14
14
 
15
+ CONNECTION.set_notice_receiver {|n| n}
16
+ CONNECTION.async_exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')
17
+
15
18
  RSpec.configure do |config|
16
19
  config.expect_with(:rspec) { |c| c.syntax = [:expect, :should] }
17
20
 
data/spec/table_spec.rb CHANGED
@@ -154,17 +154,36 @@ describe PGExaminer do
154
154
  )
155
155
  SQL
156
156
 
157
+ a.should_not == b
158
+
159
+ a.diff(b).should == {"schemas"=>{"public"=>{"tables"=>{"test_table"=>{"columns"=>{"a"=>{"type"=>{"int4"=>"text"}}}}}}}}
160
+ end
161
+
162
+ it "should consider tables with columns that have differing defaults not equivalent" do
163
+ a = examine <<-SQL
164
+ CREATE TABLE test_table (
165
+ a uuid default uuid_generate_v4(),
166
+ b timestamptz default now()
167
+ );
168
+ SQL
169
+
170
+ b = examine <<-SQL
171
+ CREATE TABLE test_table (
172
+ a uuid default uuid_generate_v4(),
173
+ b timestamptz default now()
174
+ );
175
+ SQL
176
+
157
177
  c = examine <<-SQL
158
178
  CREATE TABLE test_table (
159
- a integer default 5
179
+ a uuid,
180
+ b timestamptz default now()
160
181
  );
161
182
  SQL
162
183
 
163
- a.should_not == b
184
+ a.should == b
164
185
  a.should_not == c
165
-
166
- a.diff(b).should == {"schemas"=>{"public"=>{"tables"=>{"test_table"=>{"columns"=>{"a"=>{"type"=>{"int4"=>"text"}}}}}}}}
167
- a.diff(c).should == {"schemas"=>{"public"=>{"tables"=>{"test_table"=>{"columns"=>{"a"=>{"default"=>{nil=>"5"}}}}}}}}
186
+ a.diff(c).should == {"schemas"=>{"public"=>{"tables"=>{"test_table"=>{"columns"=>{"a"=>{"default"=>{"uuid_generate_v4()"=>nil}}}}}}}}
168
187
  end
169
188
 
170
189
  it "should consider array types as different from scalar types" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_examiner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg