db-charmer 1.8.4 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGES +19 -0
- data/README.rdoc +12 -537
- data/lib/db_charmer.rb +17 -52
- data/lib/db_charmer/active_record/class_attributes.rb +42 -27
- data/lib/db_charmer/active_record/connection_switching.rb +17 -14
- data/lib/db_charmer/active_record/db_magic.rb +3 -2
- data/lib/db_charmer/connection_factory.rb +13 -5
- data/lib/db_charmer/connection_proxy.rb +30 -1
- data/lib/db_charmer/force_slave_reads.rb +27 -8
- data/lib/db_charmer/sharding/stub_connection.rb +6 -0
- data/lib/db_charmer/version.rb +2 -2
- data/lib/db_charmer/with_remapped_databases.rb +49 -0
- data/lib/tasks/databases.rake +5 -1
- metadata +14 -26
@@ -37,6 +37,12 @@ module DbCharmer
|
|
37
37
|
@real_conn = ::ActiveRecord::Base.coerce_to_connection_proxy(conn, DbCharmer.connections_should_exist?)
|
38
38
|
end
|
39
39
|
|
40
|
+
def respond_to?(method_name, include_all = false)
|
41
|
+
return true if super
|
42
|
+
return false if real_connection.object_id == self.object_id
|
43
|
+
real_connection.respond_to?(method_name, include_all)
|
44
|
+
end
|
45
|
+
|
40
46
|
def method_missing(meth, *args, &block)
|
41
47
|
# Fail on database statements
|
42
48
|
if ::ActiveRecord::ConnectionAdapters::DatabaseStatements.instance_methods.member?(meth.to_s)
|
data/lib/db_charmer/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
module DbCharmer
|
2
|
+
def self.with_remapped_databases(mappings, &proc)
|
3
|
+
old_mappings = ::ActiveRecord::Base.db_charmer_database_remappings
|
4
|
+
begin
|
5
|
+
::ActiveRecord::Base.db_charmer_database_remappings = mappings
|
6
|
+
if mappings[:master] || mappings['master']
|
7
|
+
with_all_hijacked(&proc)
|
8
|
+
else
|
9
|
+
proc.call
|
10
|
+
end
|
11
|
+
ensure
|
12
|
+
::ActiveRecord::Base.db_charmer_database_remappings = old_mappings
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.hijack_new_classes?
|
17
|
+
!! Thread.current[:db_charmer_hijack_new_classes]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.with_all_hijacked
|
23
|
+
old_hijack_new_classes = Thread.current[:db_charmer_hijack_new_classes]
|
24
|
+
begin
|
25
|
+
Thread.current[:db_charmer_hijack_new_classes] = true
|
26
|
+
subclasses_method = DbCharmer.rails3? ? :descendants : :subclasses
|
27
|
+
::ActiveRecord::Base.send(subclasses_method).each do |subclass|
|
28
|
+
subclass.hijack_connection!
|
29
|
+
end
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
Thread.current[:db_charmer_hijack_new_classes] = old_hijack_new_classes
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#---------------------------------------------------------------------------------------------------
|
38
|
+
# Hijack connection on all new AR classes when we're in a block with main AR connection remapped
|
39
|
+
class ActiveRecord::Base
|
40
|
+
class << self
|
41
|
+
def inherited_with_hijacking(subclass)
|
42
|
+
out = inherited_without_hijacking(subclass)
|
43
|
+
hijack_connection! if DbCharmer.hijack_new_classes?
|
44
|
+
out
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method_chain :inherited, :hijacking
|
48
|
+
end
|
49
|
+
end
|
data/lib/tasks/databases.rake
CHANGED
@@ -68,7 +68,11 @@ namespace :db_charmer do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def drop_core_and_sub_database(config)
|
71
|
-
|
71
|
+
begin
|
72
|
+
drop_database(config)
|
73
|
+
rescue
|
74
|
+
$stderr.puts "#{config['database']} not exists"
|
75
|
+
end
|
72
76
|
config.each_value do | sub_config |
|
73
77
|
next unless sub_config.is_a?(Hash)
|
74
78
|
next unless sub_config['database']
|
metadata
CHANGED
@@ -1,52 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db-charmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.9.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Oleksiy Kovyrin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - <
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 4.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - <
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 4.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activerecord
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - <
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: 4.0.0
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - <
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: 4.0.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: yard
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: actionpack
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -133,6 +122,7 @@ files:
|
|
133
122
|
- lib/db_charmer/sharding/stub_connection.rb
|
134
123
|
- lib/db_charmer/sharding.rb
|
135
124
|
- lib/db_charmer/version.rb
|
125
|
+
- lib/db_charmer/with_remapped_databases.rb
|
136
126
|
- lib/db_charmer.rb
|
137
127
|
- lib/tasks/databases.rake
|
138
128
|
- init.rb
|
@@ -141,28 +131,26 @@ files:
|
|
141
131
|
- CHANGES
|
142
132
|
homepage: http://dbcharmer.net
|
143
133
|
licenses: []
|
134
|
+
metadata: {}
|
144
135
|
post_install_message:
|
145
136
|
rdoc_options:
|
146
137
|
- --charset=UTF-8
|
147
138
|
require_paths:
|
148
139
|
- lib
|
149
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
141
|
requirements:
|
152
142
|
- - ! '>='
|
153
143
|
- !ruby/object:Gem::Version
|
154
144
|
version: '0'
|
155
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
-
none: false
|
157
146
|
requirements:
|
158
147
|
- - ! '>='
|
159
148
|
- !ruby/object:Gem::Version
|
160
149
|
version: '0'
|
161
150
|
requirements: []
|
162
151
|
rubyforge_project:
|
163
|
-
rubygems_version: 1.
|
152
|
+
rubygems_version: 2.1.10
|
164
153
|
signing_key:
|
165
|
-
specification_version:
|
154
|
+
specification_version: 4
|
166
155
|
summary: ActiveRecord Connections Magic (slaves, multiple connections, etc)
|
167
156
|
test_files: []
|
168
|
-
has_rdoc:
|