rails-pg_trigger 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/pg_trigger/generator.rb +1 -1
- data/lib/pg_trigger/trigger.rb +19 -3
- data/lib/pg_trigger/version.rb +1 -1
- data/lib/pg_trigger.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f40387dfea07ab95c4dca20f9b26c2af48fd1fda8dffcb360048fa409a08d32
|
4
|
+
data.tar.gz: 17b3356c9bc2ebb418921bab81e7d6722d03dc47021e4a47be6657f4014b804d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 842f7827eaa749632f4f6e58fc8345f6bf3e6f084d8ed2e197703a548c6e373a837a0b626e2e262eaf91c9bb4395dc7ea0eb73277ce7172124d883a05843fa86
|
7
|
+
data.tar.gz: db8e8a003a9e4236683568c13686f228c8acb56a05948d7e795c8bd5364ebdaec7e388a110b21f428f074aa53c1fc8cc4bbde973a00011e921966c4b605c1a56
|
data/CHANGELOG.md
CHANGED
data/lib/pg_trigger/generator.rb
CHANGED
data/lib/pg_trigger/trigger.rb
CHANGED
@@ -26,7 +26,7 @@ module PgTrigger
|
|
26
26
|
"(?<timing>AFTER|BEFORE)",
|
27
27
|
"(?<events>(?:INSERT|UPDATE|DELETE)(?: OR (?:INSERT|UPDATE|DELETE))?)",
|
28
28
|
"(?:OF(?<columns>(?:\\s[a-z0-9_]+,?)+)\\s)?ON (?:[\\w\"]+\\.)?(?<table>\\w+)",
|
29
|
-
"FOR EACH ROW(?: WHEN \\((?<where
|
29
|
+
"FOR EACH ROW(?: WHEN \\((?<where>\\(?[^\\)]+\\)?)\\))?",
|
30
30
|
"EXECUTE FUNCTION (?:\\w+\\.)?(?<fn>\\w+)",
|
31
31
|
].join("\\s")
|
32
32
|
.yield_self { |str| Regexp.new(str) }
|
@@ -51,7 +51,10 @@ module PgTrigger
|
|
51
51
|
trigger.where(where)
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
if match[:fn] != match[:name]
|
55
|
+
trigger.nowrap { "#{match[:fn]}()" }
|
56
|
+
end
|
57
|
+
|
55
58
|
trigger
|
56
59
|
end
|
57
60
|
end
|
@@ -88,6 +91,9 @@ module PgTrigger
|
|
88
91
|
end
|
89
92
|
|
90
93
|
def where(condition)
|
94
|
+
if condition.start_with?("NOT", "not")
|
95
|
+
raise AmbiguousConditionError, "when condition starting with a NOT should be enclosed in parenthesis"
|
96
|
+
end
|
91
97
|
@where = condition
|
92
98
|
end
|
93
99
|
|
@@ -125,6 +131,10 @@ module PgTrigger
|
|
125
131
|
!@options[:nowrap]
|
126
132
|
end
|
127
133
|
|
134
|
+
def nowrap?
|
135
|
+
@options[:nowrap]
|
136
|
+
end
|
137
|
+
|
128
138
|
def create_function_sql
|
129
139
|
str = IndentedString.new(size: 4)
|
130
140
|
str += @content
|
@@ -141,6 +151,12 @@ module PgTrigger
|
|
141
151
|
end
|
142
152
|
|
143
153
|
def create_trigger_sql
|
154
|
+
action = if create_function?
|
155
|
+
"#{name}();"
|
156
|
+
else
|
157
|
+
@content
|
158
|
+
end
|
159
|
+
|
144
160
|
sql = "CREATE TRIGGER #{name}\n"
|
145
161
|
sql << @timing.to_s.upcase
|
146
162
|
sql << " #{events.map(&:upcase).join(" OR ")} "
|
@@ -148,7 +164,7 @@ module PgTrigger
|
|
148
164
|
sql << "ON #{adapter.quote_table_name(@table)}\n"
|
149
165
|
sql << "FOR EACH ROW\n"
|
150
166
|
sql << "WHEN (#{@where})\n" unless @where.nil?
|
151
|
-
sql << "EXECUTE FUNCTION #{
|
167
|
+
sql << "EXECUTE FUNCTION #{action}"
|
152
168
|
|
153
169
|
sql
|
154
170
|
end
|
data/lib/pg_trigger/version.rb
CHANGED
data/lib/pg_trigger.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "pg_trigger/railtie"
|
|
5
5
|
|
6
6
|
module PgTrigger
|
7
7
|
class InvalidTriggerDefinition < StandardError; end
|
8
|
+
class AmbiguousConditionError < StandardError; end
|
8
9
|
|
9
10
|
class << self
|
10
11
|
attr_accessor :structure_file_path, :schema, :migrations_path, :raise_on_invalid_definition
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-pg_trigger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ccocchi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -104,7 +104,7 @@ metadata:
|
|
104
104
|
homepage_uri: https://github.com/ccocchi/rails-pg_trigger
|
105
105
|
source_code_uri: https://github.com/ccocchi/rails-pg_trigger
|
106
106
|
changelog_uri: https://github.com/ccocchi/rails-pg_trigger/blob/main/CHANGELOG.md
|
107
|
-
post_install_message:
|
107
|
+
post_install_message:
|
108
108
|
rdoc_options: []
|
109
109
|
require_paths:
|
110
110
|
- lib
|
@@ -119,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
|
-
rubygems_version: 3.
|
123
|
-
signing_key:
|
122
|
+
rubygems_version: 3.3.7
|
123
|
+
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Postgres triggers for Rails
|
126
126
|
test_files: []
|