hairtrigger 0.2.19 → 0.2.20

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: f42f7d04b773f6a0ce1f5acc86e90746f35322b1
4
- data.tar.gz: d05ccf70ece346e5e73ed4433e11dc678c0bd6e9
3
+ metadata.gz: f8b4e42be78944baeb498703bd62358dc5e496fd
4
+ data.tar.gz: 44fffb42e6f6a47afa81b0383b793f75ac93a594
5
5
  SHA512:
6
- metadata.gz: 5d78e2251de79e05fdd17f1194b7f3ac7afd1711bd5cd5a40fd0205f39f4f884ca63839152e45d3a70bc60c50f2210fef4a9a6ff72e736ba05c69f0d78bda570
7
- data.tar.gz: 970c56031d52a6ad9f355e97dcad81f877ccf806a9bc4a7d6d1a659b5a5e0c04cc9505251be5982a126e625e227859c99217c3ef140678a889915a0a8f806ca2
6
+ metadata.gz: 4076623ae117821f499bc3b8854085c2fb9fb107106ff53f2a2a7fb9dd33d4e368181db5817f5f317995486bbd74db343a9c32932432acc3dbff268d6a57a261
7
+ data.tar.gz: 07297019167a8320348100210225785d15c9631d37d585f1fcc338b8e782f49b9c088dc024870be3dbdda06e40bca511f7918145c0bc7008f8cc4ed9a71819c8
data/README.md CHANGED
@@ -325,4 +325,4 @@ existing trigger if you wish to redefine it.
325
325
 
326
326
  ## Copyright
327
327
 
328
- Copyright (c) 2011-2015 Jon Jensen. See LICENSE.txt for further details.
328
+ Copyright (c) 2011-2017 Jon Jensen. See LICENSE.txt for further details.
@@ -1,4 +1,5 @@
1
1
  require 'ostruct'
2
+ require 'fileutils'
2
3
  require 'active_record'
3
4
  require 'hair_trigger/base'
4
5
  require 'hair_trigger/migrator'
@@ -140,6 +141,7 @@ module HairTrigger
140
141
  migration_name = infer_migration_name(migration_names, up_create_triggers, up_drop_triggers)
141
142
  migration_version = infer_migration_version(migration_name)
142
143
  file_name = migration_path + '/' + migration_version + "_" + migration_name.underscore + ".rb"
144
+ FileUtils.mkdir_p migration_path
143
145
  prefix = ActiveRecord::VERSION::STRING < "3.1." ? "self." : ""
144
146
  File.open(file_name, "w"){ |f| f.write <<-MIGRATION }
145
147
  # This migration was auto-generated via `rake db:generate_trigger_migration'.
@@ -427,7 +427,7 @@ END;
427
427
  raise GenerationError, "declare cannot be used in conjunction with nowrap" if options[:nowrap] && options[:declare]
428
428
  raise GenerationError, "security cannot be used in conjunction with nowrap" if options[:nowrap] && options[:security]
429
429
  raise GenerationError, "where can only be used in conjunction with nowrap on postgres 9.0 and greater" if options[:nowrap] && prepared_where && db_version < 90000
430
- raise GenerationError, "of can only be used in conjunction with nowrap on postgres 9.1 and greater" if options[:nowrap] && options[:of] && db_version < 91000
430
+ raise GenerationError, "of can only be used in conjunction with nowrap on postgres 9.1 and greater" if options[:nowrap] && options[:of] && db_version < 90100
431
431
 
432
432
  sql = ''
433
433
 
@@ -1,23 +1,25 @@
1
1
  module HairTrigger
2
2
  module Migrator
3
- def proper_table_name_with_hash_awareness(*args)
4
- name = args.first
5
- return name if name.is_a?(Hash)
6
- proper_table_name_without_hash_awareness(*args)
7
- end
8
-
9
3
  class << self
4
+ module ProperTableNameWithHashAwarenessSupport
5
+ def proper_table_name(*args)
6
+ name = args.first
7
+ return name if name.is_a?(Hash)
8
+ super
9
+ end
10
+ end
11
+
10
12
  def extended(base)
11
13
  base.class_eval do
12
14
  class << self
13
- alias_method_chain :proper_table_name, :hash_awareness
15
+ prepend ProperTableNameWithHashAwarenessSupport
14
16
  end
15
17
  end
16
18
  end
17
19
 
18
20
  def included(base)
19
21
  base.instance_eval do
20
- alias_method_chain :proper_table_name, :hash_awareness
22
+ prepend ProperTableNameWithHashAwarenessSupport
21
23
  end
22
24
  end
23
25
  end
@@ -1,13 +1,14 @@
1
1
  module HairTrigger
2
2
  module SchemaDumper
3
-
4
- def trailer_with_triggers(stream)
5
- orig_show_warnings = Builder.show_warnings
6
- Builder.show_warnings = false # we already show them when running the migration
7
- triggers(stream)
8
- trailer_without_triggers(stream)
9
- ensure
10
- Builder.show_warnings = orig_show_warnings
3
+ module TrailerWithTriggersSupport
4
+ def trailer(stream)
5
+ orig_show_warnings = Builder.show_warnings
6
+ Builder.show_warnings = false # we already show them when running the migration
7
+ triggers(stream)
8
+ super
9
+ ensure
10
+ Builder.show_warnings = orig_show_warnings
11
+ end
11
12
  end
12
13
 
13
14
  def triggers(stream)
@@ -97,7 +98,7 @@ module HairTrigger
97
98
 
98
99
  def self.included(base)
99
100
  base.class_eval do
100
- alias_method_chain :trailer, :triggers
101
+ prepend TrailerWithTriggersSupport
101
102
  class << self
102
103
  attr_accessor :previous_schema
103
104
  end
@@ -1,5 +1,5 @@
1
1
  module HairTrigger
2
- VERSION = "0.2.19"
2
+ VERSION = "0.2.20"
3
3
 
4
4
  def VERSION.<=>(other)
5
5
  split(/\./).map(&:to_i) <=> other.split(/\./).map(&:to_i)
@@ -0,0 +1,18 @@
1
+ class InitialTables < ActiveRecord::Migration
2
+ def up
3
+ create_table "users" do |t|
4
+ t.integer "group_id"
5
+ t.string "name"
6
+ end
7
+
8
+ create_table "groups" do |t|
9
+ t.integer "bob_count", :default => 0
10
+ t.integer "updated_joe_count", :default => 0
11
+ end
12
+ end
13
+
14
+ def down
15
+ drop_table "users"
16
+ drop_table "groups"
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # This migration was auto-generated via `rake db:generate_trigger_migration'.
2
+ # While you can edit this file, any changes you make to the definitions here
3
+ # will be undone by the next auto-generated trigger migration.
4
+
5
+ class UserTrigger < ActiveRecord::Migration
6
+ def up
7
+ create_trigger("users_after_insert_row_when_new_name_bob__tr", :generated => true, :compatibility => 1).
8
+ on("users").
9
+ after(:insert).
10
+ where("NEW.name = 'bob'") do
11
+ "UPDATE groups SET bob_count = bob_count + 1"
12
+ end
13
+ end
14
+
15
+ def down
16
+ drop_trigger("users_after_insert_row_when_new_name_bob__tr", "users")
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ class ManualUserTrigger < ActiveRecord::Migration
2
+ def up
3
+ create_trigger(:compatibility => 1).
4
+ on("users").
5
+ after(:update).
6
+ where("NEW.name = 'joe'") do
7
+ "UPDATE groups SET updated_joe_count = updated_joe_count + 1"
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
- class InitialTables < ActiveRecord::Migration
1
+ class InitialTables < ActiveRecord::Migration[5.0]
2
2
  def up
3
3
  create_table "users" do |t|
4
4
  t.integer "group_id"
@@ -2,7 +2,7 @@
2
2
  # While you can edit this file, any changes you make to the definitions here
3
3
  # will be undone by the next auto-generated trigger migration.
4
4
 
5
- class UserTrigger < ActiveRecord::Migration
5
+ class UserTrigger < ActiveRecord::Migration[5.0]
6
6
  def up
7
7
  create_trigger("users_after_insert_row_when_new_name_bob__tr", :generated => true, :compatibility => 1).
8
8
  on("users").
@@ -1,4 +1,4 @@
1
- class ManualUserTrigger < ActiveRecord::Migration
1
+ class ManualUserTrigger < ActiveRecord::Migration[5.0]
2
2
  def up
3
3
  create_trigger(:compatibility => 1).
4
4
  on("users").
@@ -39,7 +39,17 @@ shared_context "hairtrigger utils" do
39
39
  FileUtils.mkdir_p(HairTrigger.migration_path)
40
40
  FileUtils.cp_r('spec/models', 'tmp')
41
41
  reset_models
42
- FileUtils.cp_r(Dir.glob("spec/migrations#{ActiveRecord::VERSION::STRING < "3.1." ? "-pre-3.1" : ""}/#{options[:migration_glob]}"), HairTrigger.migration_path)
42
+ FileUtils.cp_r(Dir.glob("spec/migrations#{migrations_sufix}/#{options[:migration_glob]}"), HairTrigger.migration_path)
43
+ end
44
+
45
+ def migrations_sufix
46
+ if ActiveRecord::VERSION::STRING < '3.1.'
47
+ '-pre-3.1'
48
+ elsif ActiveRecord::VERSION::STRING < '5.0'
49
+ '-3.2'
50
+ else
51
+ ''
52
+ end
43
53
  end
44
54
 
45
55
  def initialize_db
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hairtrigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-26 00:00:00.000000000 Z
11
+ date: 2017-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.8'
33
+ version: '3.10'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.8'
40
+ version: '3.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby2ruby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.3'
47
+ version: '2.4'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.3'
54
+ version: '2.4'
55
55
  description: allows you to declare database triggers in ruby in your models, and then
56
56
  generate appropriate migrations as they change
57
57
  email: jenseng@gmail.com
@@ -75,6 +75,9 @@ files:
75
75
  - lib/tasks/hair_trigger.rake
76
76
  - spec/adapter_spec.rb
77
77
  - spec/builder_spec.rb
78
+ - spec/migrations-3.2/20110331212003_initial_tables.rb
79
+ - spec/migrations-3.2/20110331212631_user_trigger.rb
80
+ - spec/migrations-3.2/20110417185102_manual_user_trigger.rb
78
81
  - spec/migrations-pre-3.1/20110331212003_initial_tables.rb
79
82
  - spec/migrations-pre-3.1/20110331212631_user_trigger.rb
80
83
  - spec/migrations-pre-3.1/20110417185102_manual_user_trigger.rb
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  version: 1.3.5
107
110
  requirements: []
108
111
  rubyforge_project:
109
- rubygems_version: 2.5.1
112
+ rubygems_version: 2.6.11
110
113
  signing_key:
111
114
  specification_version: 4
112
115
  summary: easy database triggers for active record