ar-octopus 0.1.1 → 0.1.2
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/Rakefile +1 -1
- data/ar-octopus.gemspec +2 -2
- data/lib/octopus.rb +2 -1
- data/lib/octopus/proxy.rb +2 -1
- data/spec/config/shards.yml +29 -52
- data/spec/octopus/proxy_spec.rb +4 -0
- metadata +4 -4
data/Rakefile
CHANGED
@@ -37,7 +37,7 @@ begin
|
|
37
37
|
gem.add_development_dependency "jeweler", ">= 1.4"
|
38
38
|
gem.add_development_dependency "actionpack", ">= 2.3"
|
39
39
|
gem.add_dependency('activerecord', '>= 2.3')
|
40
|
-
gem.version = "0.1.
|
40
|
+
gem.version = "0.1.2"
|
41
41
|
end
|
42
42
|
Jeweler::GemcutterTasks.new
|
43
43
|
rescue LoadError
|
data/ar-octopus.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ar-octopus}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thiago Pradi", "Mike Perham"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-02}
|
13
13
|
s.description = %q{This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards.}
|
14
14
|
s.email = %q{tchandy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/octopus.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "yaml"
|
2
|
+
require "erb"
|
2
3
|
|
3
4
|
module Octopus
|
4
5
|
def self.env()
|
@@ -10,7 +11,7 @@ module Octopus
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.config()
|
13
|
-
@config ||= HashWithIndifferentAccess.new(YAML.
|
14
|
+
@config ||= HashWithIndifferentAccess.new(YAML.load(ERB.new(File.open(Octopus.directory() + "/config/shards.yml").read()).result))[Octopus.env()]
|
14
15
|
|
15
16
|
if @config && @config['enviroments']
|
16
17
|
self.enviroments = @config['enviroments']
|
data/lib/octopus/proxy.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Octopus::Proxy
|
2
|
-
attr_accessor :current_model, :current_shard, :current_group, :block, :using_enabled, :last_current_shard
|
2
|
+
attr_accessor :current_model, :current_shard, :current_group, :block, :using_enabled, :last_current_shard, :config
|
3
3
|
|
4
4
|
def initialize(config)
|
5
5
|
initialize_shards(config)
|
@@ -10,6 +10,7 @@ class Octopus::Proxy
|
|
10
10
|
@shards = {}
|
11
11
|
@groups = {}
|
12
12
|
@shards[:master] = ActiveRecord::Base.connection_pool()
|
13
|
+
@config = ActiveRecord::Base.connection_pool.connection.instance_variable_get(:@config)
|
13
14
|
@current_shard = :master
|
14
15
|
|
15
16
|
if !config.nil? && config.has_key?("verify_connection")
|
data/spec/config/shards.yml
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
mysql: &mysql
|
2
|
+
adapter: <%= 'mysql' %>
|
3
|
+
host: localhost
|
4
|
+
|
1
5
|
octopus:
|
2
6
|
shards:
|
3
7
|
alone_shard:
|
4
|
-
adapter: mysql
|
5
|
-
host: localhost
|
6
8
|
database: octopus_shard5
|
9
|
+
<<: *mysql
|
7
10
|
|
8
11
|
postgresql_shard:
|
9
12
|
adapter: postgresql
|
@@ -18,46 +21,38 @@ octopus:
|
|
18
21
|
|
19
22
|
history_shards:
|
20
23
|
aug2009:
|
21
|
-
adapter: mysql
|
22
|
-
host: localhost
|
23
24
|
database: octopus_shard2
|
25
|
+
<<: *mysql
|
24
26
|
aug2010:
|
25
|
-
adapter: mysql
|
26
|
-
host: localhost
|
27
27
|
database: octopus_shard3
|
28
|
+
<<: *mysql
|
28
29
|
aug2011:
|
29
|
-
adapter: mysql
|
30
|
-
host: localhost
|
31
30
|
database: octopus_shard4
|
31
|
+
<<: *mysql
|
32
32
|
|
33
33
|
country_shards:
|
34
34
|
canada:
|
35
|
-
adapter: mysql
|
36
|
-
host: localhost
|
37
35
|
database: octopus_shard2
|
36
|
+
<<: *mysql
|
38
37
|
brazil:
|
39
|
-
adapter: mysql
|
40
|
-
host: localhost
|
41
38
|
database: octopus_shard3
|
39
|
+
<<: *mysql
|
42
40
|
russia:
|
43
|
-
adapter: mysql
|
44
|
-
host: localhost
|
45
41
|
database: octopus_shard4
|
42
|
+
<<: *mysql
|
46
43
|
|
47
44
|
|
48
45
|
production_raise_error:
|
49
46
|
shards:
|
50
47
|
history_shards:
|
51
48
|
duplicated_shard_name:
|
52
|
-
adapter: mysql
|
53
|
-
host: localhost
|
54
49
|
database: octopus_shard5
|
50
|
+
<<: *mysql
|
55
51
|
|
56
52
|
country_shards:
|
57
53
|
duplicated_shard_name:
|
58
|
-
adapter: mysql
|
59
|
-
host: localhost
|
60
54
|
database: octopus_shard4
|
55
|
+
<<: *mysql
|
61
56
|
|
62
57
|
production_replicated:
|
63
58
|
replicated: true
|
@@ -65,42 +60,34 @@ production_replicated:
|
|
65
60
|
|
66
61
|
shards:
|
67
62
|
slave1:
|
68
|
-
adapter: mysql
|
69
|
-
host: localhost
|
70
63
|
database: octopus_shard2
|
64
|
+
<<: *mysql
|
71
65
|
slave2:
|
72
|
-
adapter: mysql
|
73
|
-
host: localhost
|
74
66
|
database: octopus_shard3
|
67
|
+
<<: *mysql
|
75
68
|
slave3:
|
76
|
-
adapter: mysql
|
77
|
-
host: localhost
|
78
69
|
database: octopus_shard4
|
70
|
+
<<: *mysql
|
79
71
|
slave4:
|
80
|
-
adapter: mysql
|
81
|
-
host: localhost
|
82
72
|
database: octopus_shard5
|
73
|
+
<<: *mysql
|
83
74
|
|
84
75
|
|
85
76
|
production_fully_replicated:
|
86
77
|
replicated: true
|
87
78
|
shards:
|
88
79
|
slave1:
|
89
|
-
adapter: mysql
|
90
|
-
host: localhost
|
91
80
|
database: octopus_shard2
|
81
|
+
<<: *mysql
|
92
82
|
slave2:
|
93
|
-
adapter: mysql
|
94
|
-
host: localhost
|
95
83
|
database: octopus_shard3
|
84
|
+
<<: *mysql
|
96
85
|
slave3:
|
97
|
-
adapter: mysql
|
98
|
-
host: localhost
|
99
86
|
database: octopus_shard4
|
87
|
+
<<: *mysql
|
100
88
|
slave4:
|
101
|
-
adapter: mysql
|
102
|
-
host: localhost
|
103
89
|
database: octopus_shard5
|
90
|
+
<<: *mysql
|
104
91
|
|
105
92
|
octopus_rails:
|
106
93
|
replicated: true
|
@@ -111,44 +98,34 @@ octopus_rails:
|
|
111
98
|
|
112
99
|
staging:
|
113
100
|
slave1:
|
114
|
-
adapter: mysql
|
115
|
-
host: localhost
|
116
101
|
database: octopus_shard2
|
102
|
+
<<: *mysql
|
117
103
|
slave2:
|
118
|
-
adapter: mysql
|
119
|
-
host: localhost
|
120
104
|
database: octopus_shard3
|
105
|
+
<<: *mysql
|
121
106
|
|
122
107
|
production:
|
123
108
|
slave3:
|
124
|
-
adapter: mysql
|
125
|
-
host: localhost
|
126
109
|
database: octopus_shard4
|
110
|
+
<<: *mysql
|
127
111
|
slave4:
|
128
|
-
adapter: mysql
|
129
|
-
host: localhost
|
130
112
|
database: octopus_shard5
|
113
|
+
<<: *mysql
|
131
114
|
|
132
115
|
not_entire_sharded:
|
133
116
|
entire_sharded: false
|
134
117
|
shards:
|
135
118
|
europe:
|
136
|
-
adapter: mysql
|
137
|
-
host: localhost
|
138
119
|
database: octopus_shard2
|
120
|
+
<<: *mysql
|
139
121
|
canada:
|
140
|
-
adapter: mysql
|
141
|
-
host: localhost
|
142
122
|
database: octopus_shard3
|
123
|
+
<<: *mysql
|
143
124
|
brazil:
|
144
|
-
adapter: mysql
|
145
|
-
host: localhost
|
146
125
|
database: octopus_shard4
|
126
|
+
<<: *mysql
|
147
127
|
russia:
|
148
|
-
adapter: mysql
|
149
|
-
host: localhost
|
150
128
|
database: octopus_shard5
|
129
|
+
<<: *mysql
|
151
130
|
|
152
131
|
|
153
|
-
|
154
|
-
|
data/spec/octopus/proxy_spec.rb
CHANGED
@@ -20,6 +20,10 @@ describe Octopus::Proxy do
|
|
20
20
|
it "should not verify connections for default" do
|
21
21
|
proxy.instance_variable_get(:@verify_connection).should be_false
|
22
22
|
end
|
23
|
+
|
24
|
+
it "should work with thiking sphinx" do
|
25
|
+
proxy.instance_variable_get(:@config).should == {:adapter=>"mysql", :password=>"", :database=>"octopus_shard1", :username=>"root"}
|
26
|
+
end
|
23
27
|
|
24
28
|
describe "should raise error if you have duplicated shard names" do
|
25
29
|
before(:each) do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-octopus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Thiago Pradi
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-02 00:00:00 -03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|