connection_manager 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +25 -25
- data/lib/connection_manager/cross_schema_patch.rb +19 -120
- data/lib/connection_manager/version.rb +1 -1
- metadata +16 -16
data/Gemfile.lock
CHANGED
@@ -1,47 +1,47 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
connection_manager (0.2.
|
4
|
+
connection_manager (0.2.5)
|
5
5
|
activerecord (~> 3.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ZenTest (4.
|
11
|
-
activemodel (3.
|
12
|
-
activesupport (= 3.
|
10
|
+
ZenTest (4.7.0)
|
11
|
+
activemodel (3.2.3)
|
12
|
+
activesupport (= 3.2.3)
|
13
13
|
builder (~> 3.0.0)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
arel (~> 2.2.1)
|
14
|
+
activerecord (3.2.3)
|
15
|
+
activemodel (= 3.2.3)
|
16
|
+
activesupport (= 3.2.3)
|
17
|
+
arel (~> 3.0.2)
|
19
18
|
tzinfo (~> 0.3.29)
|
20
|
-
activesupport (3.
|
19
|
+
activesupport (3.2.3)
|
20
|
+
i18n (~> 0.6)
|
21
21
|
multi_json (~> 1.0)
|
22
|
-
arel (
|
22
|
+
arel (3.0.2)
|
23
23
|
autotest (4.4.6)
|
24
24
|
ZenTest (>= 4.4.1)
|
25
25
|
builder (3.0.0)
|
26
26
|
diff-lcs (1.1.3)
|
27
|
-
factory_girl (
|
28
|
-
activesupport
|
27
|
+
factory_girl (3.2.0)
|
28
|
+
activesupport (>= 3.0.0)
|
29
29
|
i18n (0.6.0)
|
30
30
|
metaclass (0.0.1)
|
31
|
-
mocha (0.
|
31
|
+
mocha (0.11.3)
|
32
32
|
metaclass (~> 0.0.1)
|
33
|
-
multi_json (1.
|
33
|
+
multi_json (1.3.2)
|
34
34
|
mysql2 (0.3.11)
|
35
|
-
rspec (2.
|
36
|
-
rspec-core (~> 2.
|
37
|
-
rspec-expectations (~> 2.
|
38
|
-
rspec-mocks (~> 2.
|
39
|
-
rspec-core (2.
|
40
|
-
rspec-expectations (2.
|
41
|
-
diff-lcs (~> 1.1.
|
42
|
-
rspec-mocks (2.
|
43
|
-
sqlite3 (1.3.
|
44
|
-
tzinfo (0.3.
|
35
|
+
rspec (2.9.0)
|
36
|
+
rspec-core (~> 2.9.0)
|
37
|
+
rspec-expectations (~> 2.9.0)
|
38
|
+
rspec-mocks (~> 2.9.0)
|
39
|
+
rspec-core (2.9.0)
|
40
|
+
rspec-expectations (2.9.1)
|
41
|
+
diff-lcs (~> 1.1.3)
|
42
|
+
rspec-mocks (2.9.0)
|
43
|
+
sqlite3 (1.3.6)
|
44
|
+
tzinfo (0.3.33)
|
45
45
|
|
46
46
|
PLATFORMS
|
47
47
|
ruby
|
@@ -1,128 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
### https://github.com/rails/rails/blob/3-0-stable/activerecord/lib/active_record/associations.rb
|
4
|
-
# ActiveRecord 3.0 ONLY
|
1
|
+
# ActiveRecord 3.0 BACK PORT ONLY
|
2
|
+
# https://github.com/brianmario/mysql2/commit/14accdf8d1bf557f652c19b870316094a7441334#diff-0
|
5
3
|
|
6
4
|
if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
|
7
|
-
|
8
5
|
module ActiveRecord
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
t_name.to_s.gsub(/.*\./, '')
|
16
|
-
end
|
17
|
-
|
18
|
-
def association_join
|
19
|
-
return @join if @join
|
20
|
-
aliased_table = Arel::Table.new(table_name.to_s.gsub(/.*\./, ''), :as => @aliased_table_name.to_s.gsub(/.*\./, ''),
|
21
|
-
:engine => arel_engine,
|
22
|
-
:columns => klass.columns)
|
23
|
-
|
24
|
-
parent_table = Arel::Table.new(parent.table_name.to_s.gsub(/.*\./, ''), :as => parent.aliased_table_name.to_s.gsub(/.*\./, ''),
|
25
|
-
:engine => arel_engine,
|
26
|
-
:columns => parent.active_record.columns)
|
27
|
-
as_conditions = reflection.options[:conditions] && process_conditions(reflection.options[:conditions], aliased_table_name)
|
28
|
-
|
29
|
-
@join = case reflection.macro
|
30
|
-
|
31
|
-
when :has_and_belongs_to_many
|
32
|
-
join_table = Arel::Table.new(options[:join_table], :as => aliased_join_table_name, :engine => arel_engine)
|
33
|
-
fk = options[:foreign_key] || reflection.active_record.to_s.foreign_key
|
34
|
-
klass_fk = options[:association_foreign_key] || klass.to_s.foreign_key
|
35
|
-
|
36
|
-
[
|
37
|
-
join_table[fk].eq(parent_table[reflection.active_record.primary_key]),
|
38
|
-
[aliased_table[klass.primary_key].eq(join_table[klass_fk]), as_conditions].reject{ |x| x.blank? }
|
39
|
-
]
|
40
|
-
when :has_many, :has_one
|
41
|
-
if reflection.options[:through]
|
42
|
-
join_table = Arel::Table.new(through_reflection.klass.table_name, :as => aliased_join_table_name, :engine => arel_engine)
|
43
|
-
jt_as_conditions = through_reflection.options[:conditions] && process_conditions(through_reflection.options[:conditions], aliased_table_name)
|
44
|
-
jt_as_extra = jt_source_extra = jt_sti_extra = nil
|
45
|
-
first_key = second_key = as_extra = nil
|
46
|
-
|
47
|
-
if through_reflection.macro == :belongs_to
|
48
|
-
jt_primary_key = through_reflection.primary_key_name
|
49
|
-
jt_foreign_key = through_reflection.association_primary_key
|
50
|
-
else
|
51
|
-
jt_primary_key = through_reflection.active_record_primary_key
|
52
|
-
jt_foreign_key = through_reflection.primary_key_name
|
53
|
-
|
54
|
-
if through_reflection.options[:as] # has_many :through against a polymorphic join
|
55
|
-
jt_as_extra = join_table[through_reflection.options[:as].to_s + '_type'].eq(parent.active_record.base_class.name)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
case source_reflection.macro
|
60
|
-
when :has_many, :has_one
|
61
|
-
if source_reflection.options[:as]
|
62
|
-
first_key = "#{source_reflection.options[:as]}_id"
|
63
|
-
second_key = options[:foreign_key] || primary_key
|
64
|
-
as_extra = aliased_table["#{source_reflection.options[:as]}_type"].eq(source_reflection.active_record.base_class.name)
|
65
|
-
else
|
66
|
-
first_key = through_reflection.klass.base_class.to_s.foreign_key
|
67
|
-
second_key = options[:foreign_key] || primary_key
|
68
|
-
end
|
69
|
-
|
70
|
-
unless through_reflection.klass.descends_from_active_record?
|
71
|
-
jt_sti_extra = join_table[through_reflection.active_record.inheritance_column].eq(through_reflection.klass.sti_name)
|
72
|
-
end
|
73
|
-
when :belongs_to
|
74
|
-
first_key = primary_key
|
75
|
-
if reflection.options[:source_type]
|
76
|
-
second_key = source_reflection.association_foreign_key
|
77
|
-
jt_source_extra = join_table[reflection.source_reflection.options[:foreign_type]].eq(reflection.options[:source_type])
|
78
|
-
else
|
79
|
-
second_key = source_reflection.primary_key_name
|
80
|
-
end
|
81
|
-
end
|
82
|
-
[
|
83
|
-
[parent_table[jt_primary_key].eq(join_table[jt_foreign_key]), jt_as_extra, jt_source_extra, jt_sti_extra, jt_as_conditions].reject{|x| x.blank? },
|
84
|
-
[aliased_table[first_key].eq(join_table[second_key]), as_extra, as_conditions].reject{ |x| x.blank? }
|
85
|
-
]
|
86
|
-
elsif reflection.options[:as]
|
87
|
-
id_rel = aliased_table["#{reflection.options[:as]}_id"].eq(parent_table[parent.primary_key])
|
88
|
-
type_rel = aliased_table["#{reflection.options[:as]}_type"].eq(parent.active_record.base_class.name)
|
89
|
-
[id_rel, type_rel, as_conditions].reject{ |x| x.blank?}
|
90
|
-
else
|
91
|
-
foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
|
92
|
-
[aliased_table[foreign_key].eq(parent_table[reflection.options[:primary_key] || parent.primary_key]), as_conditions].reject{ |x| x.blank? }
|
93
|
-
end
|
94
|
-
when :belongs_to
|
95
|
-
[aliased_table[options[:primary_key] || reflection.klass.primary_key].eq(parent_table[options[:foreign_key] || reflection.primary_key_name] || find_belongs_to_arel_column(parent_table)), as_conditions].reject{ |x| x.blank? }
|
96
|
-
|
97
|
-
#[aliased_table[options[:primary_key] || reflection.klass.primary_key].eq(find_belongs_to_arel_column(parent_table)), as_conditions].reject{ |x| x.blank? }
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
unless klass.descends_from_active_record?
|
102
|
-
sti_column = aliased_table[klass.inheritance_column]
|
103
|
-
sti_condition = sti_column.eq(klass.sti_name)
|
104
|
-
klass.descendants.each {|subclass| sti_condition = sti_condition.or(sti_column.eq(subclass.sti_name)) }
|
105
|
-
|
106
|
-
@join << sti_condition
|
107
|
-
end
|
108
|
-
|
109
|
-
@join
|
110
|
-
end
|
111
|
-
|
112
|
-
def find_belongs_to_arel_column(parent_table)
|
113
|
-
parent_table.columns.select{|c| (c.name == (options[:foreign_key] || reflection.primary_key_name).to_sym)}[0]
|
114
|
-
end
|
6
|
+
module ConnectionAdapters
|
7
|
+
class Mysql2Adapter < AbstractAdapter
|
8
|
+
def tables(name = nil, database = nil) #:nodoc:
|
9
|
+
sql = ["SHOW TABLES", database].compact.join(' IN ')
|
10
|
+
execute(sql, 'SCHEMA').collect do |field|
|
11
|
+
field.first
|
115
12
|
end
|
116
13
|
end
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
14
|
+
|
15
|
+
def table_exists?(name)
|
16
|
+
return true if super
|
17
|
+
name = name.to_s
|
18
|
+
schema, table = name.split('.', 2)
|
19
|
+
unless table # A table was provided without a schema
|
20
|
+
table = schema
|
21
|
+
schema = nil
|
22
|
+
end
|
23
|
+
tables(nil, schema).include? table
|
24
|
+
end
|
126
25
|
end
|
127
26
|
end
|
128
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connection_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70098201041480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70098201041480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70098201041000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70098201041000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70098201040540 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70098201040540
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: autotest
|
49
|
-
requirement: &
|
49
|
+
requirement: &70098201040000 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70098201040000
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70098201039580 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70098201039580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: factory_girl
|
71
|
-
requirement: &
|
71
|
+
requirement: &70098201039100 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70098201039100
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mysql2
|
82
|
-
requirement: &
|
82
|
+
requirement: &70098201038680 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70098201038680
|
91
91
|
description: Simplifies connecting to Muliple and Replication databases with rails
|
92
92
|
and active_record
|
93
93
|
email:
|