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 +4 -4
- data/README.md +1 -1
- data/lib/hair_trigger.rb +2 -0
- data/lib/hair_trigger/builder.rb +1 -1
- data/lib/hair_trigger/migrator.rb +10 -8
- data/lib/hair_trigger/schema_dumper.rb +10 -9
- data/lib/hair_trigger/version.rb +1 -1
- data/spec/migrations-3.2/20110331212003_initial_tables.rb +18 -0
- data/spec/migrations-3.2/20110331212631_user_trigger.rb +18 -0
- data/spec/migrations-3.2/20110417185102_manual_user_trigger.rb +10 -0
- data/spec/migrations/20110331212003_initial_tables.rb +1 -1
- data/spec/migrations/20110331212631_user_trigger.rb +1 -1
- data/spec/migrations/20110417185102_manual_user_trigger.rb +1 -1
- data/spec/spec_helper.rb +11 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8b4e42be78944baeb498703bd62358dc5e496fd
|
4
|
+
data.tar.gz: 44fffb42e6f6a47afa81b0383b793f75ac93a594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4076623ae117821f499bc3b8854085c2fb9fb107106ff53f2a2a7fb9dd33d4e368181db5817f5f317995486bbd74db343a9c32932432acc3dbff268d6a57a261
|
7
|
+
data.tar.gz: 07297019167a8320348100210225785d15c9631d37d585f1fcc338b8e782f49b9c088dc024870be3dbdda06e40bca511f7918145c0bc7008f8cc4ed9a71819c8
|
data/README.md
CHANGED
data/lib/hair_trigger.rb
CHANGED
@@ -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'.
|
data/lib/hair_trigger/builder.rb
CHANGED
@@ -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 <
|
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
|
-
|
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
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
101
|
+
prepend TrailerWithTriggersSupport
|
101
102
|
class << self
|
102
103
|
attr_accessor :previous_schema
|
103
104
|
end
|
data/lib/hair_trigger/version.rb
CHANGED
@@ -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
|
@@ -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").
|
data/spec/spec_helper.rb
CHANGED
@@ -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#{
|
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.
|
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-
|
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.
|
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.
|
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.
|
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.
|
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.
|
112
|
+
rubygems_version: 2.6.11
|
110
113
|
signing_key:
|
111
114
|
specification_version: 4
|
112
115
|
summary: easy database triggers for active record
|