sequel_postgresql_triggers 1.0.7 → 1.0.8
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 +4 -4
- data/lib/sequel_postgresql_triggers.rb +8 -8
- data/spec/sequel_postgresql_triggers_spec.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a05702b972f0adb894a4c5e678400debab6f7a
|
4
|
+
data.tar.gz: cd51e2bf9105506ed4d992a2eafa231c45346ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfcd7fe87e24a790f79c1158fabd01f38f0411ad4632e5b4c2a18cce5e27dab8cb32832f8b3a8edd14d879f6427e6bd00c231409db5f2740b8dd9104cc5be833
|
7
|
+
data.tar.gz: ff1c7f9c541f44e00217e65ed434a16b45e1418517f47e76c1df84590a548fc021f5d3a54454ddca403256c1dc80c2f55b4d0b8ebf202097eceb4d475a8829aa
|
@@ -37,7 +37,7 @@ module Sequel
|
|
37
37
|
BEGIN
|
38
38
|
IF (TG_OP = 'UPDATE' AND (NEW.#{id_column} = OLD.#{id_column} OR (OLD.#{id_column} IS NULL AND NEW.#{id_column} IS NULL))) THEN
|
39
39
|
RETURN NEW;
|
40
|
-
ELSE
|
40
|
+
ELSE
|
41
41
|
IF ((TG_OP = 'INSERT' OR TG_OP = 'UPDATE') AND NEW.#{id_column} IS NOT NULL) THEN
|
42
42
|
UPDATE #{table} SET #{count_column} = #{count_column} + 1 WHERE #{main_column} = NEW.#{id_column};
|
43
43
|
END IF;
|
@@ -53,7 +53,7 @@ module Sequel
|
|
53
53
|
END;
|
54
54
|
SQL
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Turns a column in the table into a created at timestamp column, which
|
58
58
|
# always contains the timestamp the record was inserted into the database.
|
59
59
|
# Arguments:
|
@@ -75,7 +75,7 @@ module Sequel
|
|
75
75
|
END;
|
76
76
|
SQL
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# Makes all given columns in the given table immutable, so an exception
|
80
80
|
# is raised if there is an attempt to modify the value when updating the
|
81
81
|
# record. Arguments:
|
@@ -90,13 +90,13 @@ module Sequel
|
|
90
90
|
new = "NEW.#{quote_identifier(c)}"
|
91
91
|
<<-END
|
92
92
|
IF #{new} IS DISTINCT FROM #{old} THEN
|
93
|
-
RAISE EXCEPTION 'Attempted
|
93
|
+
RAISE EXCEPTION 'Attempted #{c} update: Old: %, New: %', #{old}, #{new};
|
94
94
|
END IF;
|
95
95
|
END
|
96
96
|
end.join("\n")
|
97
97
|
pgt_trigger(table, trigger_name, function_name, :update, "BEGIN #{ifs} RETURN NEW; END;")
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
# Turns a column in the main table into a sum cache. A sum cache is a
|
101
101
|
# column in the main table with the sum of a column in the summed table
|
102
102
|
# for the matching id. Arguments:
|
@@ -176,7 +176,7 @@ module Sequel
|
|
176
176
|
SQL
|
177
177
|
pgt_trigger(main_table, trigger_name, function_name, [:insert, :delete, :update], sql, :after=>true)
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
# Turns a column in the table into a updated at timestamp column, which
|
181
181
|
# always contains the timestamp the record was inserted or last updated.
|
182
182
|
# Arguments:
|
@@ -193,9 +193,9 @@ module Sequel
|
|
193
193
|
END;
|
194
194
|
SQL
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
private
|
198
|
-
|
198
|
+
|
199
199
|
# Add or replace a function that returns trigger to handle the action,
|
200
200
|
# and add a trigger that calls the function.
|
201
201
|
def pgt_trigger(table, trigger_name, function_name, events, definition, opts={})
|
@@ -7,6 +7,17 @@ DB = Sequel.connect(ENV['PGT_SPEC_DB']||'postgres:///spgt_test?user=postgres')
|
|
7
7
|
$:.unshift(File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib'))
|
8
8
|
require 'sequel_postgresql_triggers'
|
9
9
|
|
10
|
+
if defined?(RSpec)
|
11
|
+
require 'rspec/version'
|
12
|
+
if RSpec::Version::STRING >= '2.11.0'
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.expect_with :rspec do |c|
|
15
|
+
c.syntax = :should
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
describe "PostgreSQL Triggers" do
|
11
22
|
before do
|
12
23
|
DB.create_language(:plpgsql) if DB.server_version < 90000
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_postgresql_triggers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.4.5
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Database enforced timestamps, immutable columns, and counter/sum caches
|