hairtrigger 0.2.10 → 0.2.11

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.
data/README.md CHANGED
@@ -276,6 +276,22 @@ User.triggers.each(&:validate!)
276
276
  HairTrigger does not validate your SQL, so be sure to test it in all databases
277
277
  you want to support.
278
278
 
279
+ ### PostgreSQL NOTICEs
280
+
281
+ When running a trigger migration, you might notice some PostgreSQL
282
+ NOTICEs like so:
283
+
284
+ ```
285
+ NOTICE: trigger "foo_bar_baz" for table "quux" does not exist, skipping
286
+ NOTICE: function foo_bar_baz() does not exist, skipping
287
+ ```
288
+
289
+ This happens because HairTrigger will attempt to drop the existing
290
+ trigger/function if it already exists. These notices are safe to
291
+ ignore. Note that this behavior [may change](https://github.com/jenseng/hair_trigger/issues/28)
292
+ in a future release, meaning you'll first need to explicitly drop the
293
+ existing trigger if you wish to redefine it.
294
+
279
295
  ## Gotchas
280
296
 
281
297
  * As is the case with ActiveRecord::Base.update_all or any direct SQL you do,
@@ -301,7 +317,7 @@ you want to support.
301
317
 
302
318
  * Ruby 1.8.7+
303
319
  * Rails 2.3+
304
- * Postgres 8.0+
320
+ * PostgreSQL 8.0+
305
321
  * MySQL 5.0.10+
306
322
  * SQLite 3.3.8+
307
323
 
@@ -78,6 +78,7 @@ module HairTrigger
78
78
  end
79
79
 
80
80
  def of(*columns)
81
+ raise DeclarationError, "`of' requested, but no columns specified" unless columns.present?
81
82
  options[:of] = columns
82
83
  end
83
84
 
@@ -303,6 +304,12 @@ module HairTrigger
303
304
  "on(#{options[:table].inspect})"
304
305
  when :where
305
306
  "where(#{prepared_where.inspect})"
307
+ when :of
308
+ "of(#{options[:of].inspect[1..-2]})"
309
+ when :for_each
310
+ "for_each(#{options[:for_each].downcase.to_sym.inspect})"
311
+ when :declare
312
+ "declare(#{options[:declarations].inspect})"
306
313
  else
307
314
  "#{c}(#{options[c].inspect})"
308
315
  end
@@ -1,5 +1,5 @@
1
1
  module HairTrigger
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.11"
3
3
 
4
4
  def VERSION.<=>(other)
5
5
  split(/\./).map(&:to_i) <=> other.split(/\./).map(&:to_i)
@@ -184,6 +184,24 @@ describe "builder" do
184
184
  builder.on(:foos).after(:truncate){ "FOO" }.generate
185
185
  }.should raise_error
186
186
  end
187
+
188
+ describe "#to_ruby" do
189
+ it "should fully represent the builder" do
190
+ code = <<-CODE.strip.gsub(/^ +/, '')
191
+ on("foos").
192
+ security(:definer).
193
+ for_each(:row).
194
+ before(:update) do |t|
195
+ t.where("NEW.foo") do
196
+ "FOO;"
197
+ end
198
+ end
199
+ CODE
200
+ b = builder
201
+ b.instance_eval(code)
202
+ b.to_ruby.strip.gsub(/^ +/, '').should be_include(code)
203
+ end
204
+ end
187
205
  end
188
206
 
189
207
  context "postgresql" do
@@ -308,6 +326,25 @@ describe "builder" do
308
326
  should include("IF NEW.bar <> OLD.bar OR (NEW.bar IS NULL) <> (OLD.bar IS NULL) THEN")
309
327
  end
310
328
  end
329
+
330
+ describe "#to_ruby" do
331
+ it "should fully represent the builder" do
332
+ code = <<-CODE.strip.gsub(/^ +/, '')
333
+ on("foos").
334
+ of("bar").
335
+ security(:invoker).
336
+ for_each(:row).
337
+ before(:update) do |t|
338
+ t.where("NEW.foo").declare("row RECORD") do
339
+ "FOO;"
340
+ end
341
+ end
342
+ CODE
343
+ b = builder
344
+ b.instance_eval(code)
345
+ b.to_ruby.strip.gsub(/^ +/, '').should be_include(code)
346
+ end
347
+ end
311
348
  end
312
349
 
313
350
  context "sqlite" do
@@ -371,5 +408,22 @@ describe "builder" do
371
408
  builder.on(:foos).after(:truncate){ "FOO" }.generate
372
409
  }.should raise_error
373
410
  end
411
+
412
+ describe "#to_ruby" do
413
+ it "should fully represent the builder" do
414
+ code = <<-CODE.strip.gsub(/^ +/, '')
415
+ on("foos").
416
+ of("bar").
417
+ before(:update) do |t|
418
+ t.where("NEW.foo") do
419
+ "FOO;"
420
+ end
421
+ end
422
+ CODE
423
+ b = builder
424
+ b.instance_eval(code)
425
+ b.to_ruby.strip.gsub(/^ +/, '').should be_include(code)
426
+ end
427
+ end
374
428
  end
375
429
  end
@@ -46,7 +46,7 @@ describe "schema dumping" do
46
46
  end
47
47
  end
48
48
 
49
- context "without schema.rb" do
49
+ context "with schema.rb" do
50
50
  before do
51
51
  ActiveRecord::SchemaDumper.previous_schema = dump_schema
52
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hairtrigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-24 00:00:00.000000000 Z
12
+ date: 2014-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -59,102 +59,6 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.0.6
62
- - !ruby/object:Gem::Dependency
63
- name: rake
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: rspec
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- version: 2.14.0
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 2.14.0
94
- - !ruby/object:Gem::Dependency
95
- name: mysql
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: 2.9.1
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 2.9.1
110
- - !ruby/object:Gem::Dependency
111
- name: mysql2
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: 0.3.11
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: 0.3.11
126
- - !ruby/object:Gem::Dependency
127
- name: pg
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: 0.15.1
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: 0.15.1
142
- - !ruby/object:Gem::Dependency
143
- name: sqlite3
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: 1.3.7
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: 1.3.7
158
62
  description: allows you to declare database triggers in ruby in your models, and then
159
63
  generate appropriate migrations as they change
160
64
  email: jenseng@gmail.com