pg_triggers 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0704c4d2367210950157af18d6a2c692d17bf29b
4
- data.tar.gz: 7f206a2a7168e50eed29bf5cad05223c969614d0
3
+ metadata.gz: b034106ce8a65ee639d4de7d52bc301015f52667
4
+ data.tar.gz: 2b304f1eb3e7c3821dcf18af82d31eab1cec3d6f
5
5
  SHA512:
6
- metadata.gz: 47cd88a1cb97608e5a19dbb165bf5ce5df649d61d788bd9e54e103213e4e54cce95b5bb36cbd6adc298ee5c296036bcdd11b19889650f68fdabeab928ff9f24c
7
- data.tar.gz: b4fd38c0b2c8230cfeec1b95bdf908354b0ae2916c2e43624652e93655e22dc3dfd2afb9356c812fcfea7b5b0aa9f4784688f68c5e5299bb70916f0130d1dd1d
6
+ metadata.gz: 836e6c8c91bcef26d189c455327c9961dc0c6538540e97c4dd64a39059f5f08fc1b8d63eb413217871cd02622952611e27ab268a7fb646b1a66dd6d233fba163
7
+ data.tar.gz: d6f94920e13859f42a363184daa5096b61140ddd2bf381f8f0cafda0ba826fa0dcbd7610db3ef668f87d6b7c400d521d4c83fe192dc0f4078d398e4575076579
data/lib/pg_triggers.rb CHANGED
@@ -5,14 +5,14 @@ module PgTriggers
5
5
  def counter_cache(main_table, counter_column, counted_table, relationship, options = {})
6
6
  where = proc { |source| relationship.map{|k, v| "#{k} = #{source}.#{v}"}.join(' AND ') }
7
7
  columns = relationship.values
8
- changed = columns.map{|c| "((OLD.#{c} <> NEW.#{c}) OR (OLD.#{c} IS NULL <> NEW.#{c} IS NULL))"}.join(' OR ')
8
+ changed = columns.map{|c| "((OLD.#{c} <> NEW.#{c}) OR ((OLD.#{c} IS NULL) <> (NEW.#{c} IS NULL)))"}.join(' OR ')
9
9
  value = (options[:value] || 1).to_i
10
10
  name = options[:name] || "pt_cc_#{main_table}_#{counter_column}"
11
11
 
12
12
  condition = proc do |source|
13
13
  a = []
14
- a << columns.map{|c| "#{source}.#{c} IS NOT NULL"}.join(' AND ')
15
- a << options[:where].gsub('ROW.', "#{source}.") if options[:where]
14
+ a << "(#{columns.map{|c| "(#{source}.#{c} IS NOT NULL)"}.join(' AND ')})"
15
+ a << "(#{options[:where].gsub('ROW.', "#{source}.")})" if options[:where]
16
16
  a.join(' AND ')
17
17
  end
18
18
 
@@ -56,14 +56,14 @@ module PgTriggers
56
56
  def sum_cache(main_table, sum_column, summed_table, summed_column, relationship, options = {})
57
57
  where = proc { |source| relationship.map{|k, v| "#{k} = #{source}.#{v}"}.join(' AND ') }
58
58
  columns = relationship.values
59
- changed = columns.map{|c| "((OLD.#{c} <> NEW.#{c}) OR (OLD.#{c} IS NULL <> NEW.#{c} IS NULL))"}.join(' OR ')
59
+ changed = columns.map{|c| "((OLD.#{c} <> NEW.#{c}) OR ((OLD.#{c} IS NULL) <> (NEW.#{c} IS NULL)))"}.join(' OR ')
60
60
  multiplier = (options[:multiplier] || 1).to_i
61
61
  name = options[:name] || "pt_sc_#{main_table}_#{sum_column}"
62
62
 
63
63
  condition = proc do |source|
64
64
  a = []
65
- a << columns.map{|c| "#{source}.#{c} IS NOT NULL"}.join(' AND ')
66
- a << options[:where].gsub('ROW.', "#{source}.") if options[:where]
65
+ a << "(#{columns.map{|c| "#{source}.#{c} IS NOT NULL"}.join(' AND ')})"
66
+ a << "(#{options[:where].gsub('ROW.', "#{source}.")})" if options[:where]
67
67
  a.join(' AND ')
68
68
  end
69
69
 
@@ -1,3 +1,3 @@
1
1
  module PgTriggers
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -57,7 +57,7 @@ describe PgTriggers, 'auditing' do
57
57
  JSON.parse(r4[:changes]).should == {'item_count' => 1}
58
58
  end
59
59
 
60
- it "should always record the values of columns in the :always set" do
60
+ it "should always record the values of columns in the :include set" do
61
61
  DB.run PgTriggers.audit_table(:audited_table, include: [:id, :item_count])
62
62
 
63
63
  id = DB[:audited_table].insert
@@ -19,7 +19,7 @@ describe PgTriggers, 'updated_at' do
19
19
  # The result of now() is the time the transaction began.
20
20
  t = nil
21
21
  DB.transaction do
22
- t = DB.get{now{}}
22
+ t = DB.get{now.function}
23
23
  DB[:updated_at_table].insert(integer_column: 1)
24
24
  DB[:updated_at_table].get(:updated_at).should == t
25
25
  end
@@ -31,7 +31,7 @@ describe PgTriggers, 'updated_at' do
31
31
  t = nil
32
32
  id = DB[:updated_at_table].insert(integer_column: 1)
33
33
  DB.transaction do
34
- t = DB.get{now{}}
34
+ t = DB.get{now.function}
35
35
  DB[:updated_at_table].update integer_column: 2
36
36
  DB[:updated_at_table].get(:updated_at).should == t
37
37
  end
@@ -43,7 +43,7 @@ describe PgTriggers, 'updated_at' do
43
43
  DB[:updated_at_table].insert(integer_column: 1)
44
44
  t = nil
45
45
  DB.transaction do
46
- t = DB.get{now{}}
46
+ t = DB.get{now.function}
47
47
  DB[:updated_at_table].update integer_column: 1
48
48
  DB[:updated_at_table].get(:updated_at).should == t
49
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_triggers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.4.5
138
+ rubygems_version: 2.6.14
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Helpers for Postgres Triggers