misha-ar-octopus 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +46 -0
  5. data/.rubocop_todo.yml +56 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +18 -0
  8. data/Appraisals +16 -0
  9. data/Gemfile +4 -0
  10. data/README.mkdn +242 -0
  11. data/Rakefile +172 -0
  12. data/TODO.txt +7 -0
  13. data/ar-octopus.gemspec +42 -0
  14. data/gemfiles/rails32.gemfile +7 -0
  15. data/gemfiles/rails4.gemfile +7 -0
  16. data/gemfiles/rails41.gemfile +7 -0
  17. data/gemfiles/rails42.gemfile +7 -0
  18. data/init.rb +1 -0
  19. data/lib/ar-octopus.rb +1 -0
  20. data/lib/octopus.rb +181 -0
  21. data/lib/octopus/abstract_adapter.rb +35 -0
  22. data/lib/octopus/association.rb +13 -0
  23. data/lib/octopus/association_shard_tracking.rb +114 -0
  24. data/lib/octopus/collection_association.rb +11 -0
  25. data/lib/octopus/collection_proxy.rb +16 -0
  26. data/lib/octopus/exception.rb +4 -0
  27. data/lib/octopus/has_and_belongs_to_many_association.rb +9 -0
  28. data/lib/octopus/load_balancing.rb +4 -0
  29. data/lib/octopus/load_balancing/round_robin.rb +20 -0
  30. data/lib/octopus/log_subscriber.rb +22 -0
  31. data/lib/octopus/migration.rb +168 -0
  32. data/lib/octopus/model.rb +210 -0
  33. data/lib/octopus/persistence.rb +39 -0
  34. data/lib/octopus/proxy.rb +534 -0
  35. data/lib/octopus/railtie.rb +11 -0
  36. data/lib/octopus/relation_proxy.rb +35 -0
  37. data/lib/octopus/scope_proxy.rb +61 -0
  38. data/lib/octopus/shard_tracking.rb +41 -0
  39. data/lib/octopus/shard_tracking/attribute.rb +22 -0
  40. data/lib/octopus/shard_tracking/dynamic.rb +11 -0
  41. data/lib/octopus/singular_association.rb +9 -0
  42. data/lib/octopus/slave_group.rb +13 -0
  43. data/lib/octopus/version.rb +3 -0
  44. data/lib/tasks/octopus.rake +16 -0
  45. data/rails/init.rb +1 -0
  46. data/sample_app/.gitignore +4 -0
  47. data/sample_app/.rspec +1 -0
  48. data/sample_app/Gemfile +20 -0
  49. data/sample_app/README +3 -0
  50. data/sample_app/README.rdoc +261 -0
  51. data/sample_app/Rakefile +7 -0
  52. data/sample_app/app/assets/images/rails.png +0 -0
  53. data/sample_app/app/assets/javascripts/application.js +15 -0
  54. data/sample_app/app/assets/stylesheets/application.css +13 -0
  55. data/sample_app/app/controllers/application_controller.rb +4 -0
  56. data/sample_app/app/helpers/application_helper.rb +2 -0
  57. data/sample_app/app/mailers/.gitkeep +0 -0
  58. data/sample_app/app/models/.gitkeep +0 -0
  59. data/sample_app/app/models/item.rb +3 -0
  60. data/sample_app/app/models/user.rb +3 -0
  61. data/sample_app/app/views/layouts/application.html.erb +14 -0
  62. data/sample_app/autotest/discover.rb +2 -0
  63. data/sample_app/config.ru +4 -0
  64. data/sample_app/config/application.rb +62 -0
  65. data/sample_app/config/boot.rb +6 -0
  66. data/sample_app/config/cucumber.yml +8 -0
  67. data/sample_app/config/database.yml +28 -0
  68. data/sample_app/config/environment.rb +5 -0
  69. data/sample_app/config/environments/development.rb +37 -0
  70. data/sample_app/config/environments/production.rb +67 -0
  71. data/sample_app/config/environments/test.rb +37 -0
  72. data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
  73. data/sample_app/config/initializers/inflections.rb +15 -0
  74. data/sample_app/config/initializers/mime_types.rb +5 -0
  75. data/sample_app/config/initializers/secret_token.rb +7 -0
  76. data/sample_app/config/initializers/session_store.rb +8 -0
  77. data/sample_app/config/initializers/wrap_parameters.rb +14 -0
  78. data/sample_app/config/locales/en.yml +5 -0
  79. data/sample_app/config/routes.rb +58 -0
  80. data/sample_app/config/shards.yml +28 -0
  81. data/sample_app/db/migrate/20100720172715_create_users.rb +15 -0
  82. data/sample_app/db/migrate/20100720172730_create_items.rb +16 -0
  83. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +11 -0
  84. data/sample_app/db/schema.rb +29 -0
  85. data/sample_app/db/seeds.rb +16 -0
  86. data/sample_app/doc/README_FOR_APP +2 -0
  87. data/sample_app/features/migrate.feature +45 -0
  88. data/sample_app/features/seed.feature +15 -0
  89. data/sample_app/features/step_definitions/seeds_steps.rb +13 -0
  90. data/sample_app/features/step_definitions/web_steps.rb +218 -0
  91. data/sample_app/features/support/database.rb +13 -0
  92. data/sample_app/features/support/env.rb +57 -0
  93. data/sample_app/features/support/paths.rb +33 -0
  94. data/sample_app/lib/assets/.gitkeep +0 -0
  95. data/sample_app/lib/tasks/.gitkeep +0 -0
  96. data/sample_app/lib/tasks/cucumber.rake +64 -0
  97. data/sample_app/log/.gitkeep +0 -0
  98. data/sample_app/public/404.html +26 -0
  99. data/sample_app/public/422.html +26 -0
  100. data/sample_app/public/500.html +26 -0
  101. data/sample_app/public/favicon.ico +0 -0
  102. data/sample_app/public/images/rails.png +0 -0
  103. data/sample_app/public/index.html +279 -0
  104. data/sample_app/public/javascripts/application.js +2 -0
  105. data/sample_app/public/javascripts/controls.js +965 -0
  106. data/sample_app/public/javascripts/dragdrop.js +974 -0
  107. data/sample_app/public/javascripts/effects.js +1123 -0
  108. data/sample_app/public/javascripts/prototype.js +4874 -0
  109. data/sample_app/public/javascripts/rails.js +118 -0
  110. data/sample_app/public/robots.txt +5 -0
  111. data/sample_app/public/stylesheets/.gitkeep +0 -0
  112. data/sample_app/script/cucumber +10 -0
  113. data/sample_app/script/rails +6 -0
  114. data/sample_app/spec/models/item_spec.rb +5 -0
  115. data/sample_app/spec/models/user_spec.rb +5 -0
  116. data/sample_app/spec/spec_helper.rb +27 -0
  117. data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
  118. data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
  119. data/sample_app/vendor/plugins/.gitkeep +0 -0
  120. data/spec/config/shards.yml +217 -0
  121. data/spec/migrations/10_create_users_using_replication.rb +9 -0
  122. data/spec/migrations/11_add_field_in_all_slaves.rb +11 -0
  123. data/spec/migrations/12_create_users_using_block.rb +23 -0
  124. data/spec/migrations/13_create_users_using_block_and_using.rb +15 -0
  125. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +11 -0
  126. data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +9 -0
  127. data/spec/migrations/1_create_users_on_master.rb +9 -0
  128. data/spec/migrations/2_create_users_on_canada.rb +11 -0
  129. data/spec/migrations/3_create_users_on_both_shards.rb +11 -0
  130. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +11 -0
  131. data/spec/migrations/5_create_users_on_multiples_groups.rb +11 -0
  132. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +11 -0
  133. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +11 -0
  134. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +11 -0
  135. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +11 -0
  136. data/spec/octopus/association_shard_tracking_spec.rb +714 -0
  137. data/spec/octopus/collection_proxy_spec.rb +16 -0
  138. data/spec/octopus/log_subscriber_spec.rb +19 -0
  139. data/spec/octopus/migration_spec.rb +115 -0
  140. data/spec/octopus/model_spec.rb +693 -0
  141. data/spec/octopus/octopus_spec.rb +123 -0
  142. data/spec/octopus/proxy_spec.rb +307 -0
  143. data/spec/octopus/relation_proxy_spec.rb +93 -0
  144. data/spec/octopus/replicated_slave_grouped_spec.rb +91 -0
  145. data/spec/octopus/replication_spec.rb +137 -0
  146. data/spec/octopus/scope_proxy_spec.rb +63 -0
  147. data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +55 -0
  148. data/spec/octopus/sharded_spec.rb +33 -0
  149. data/spec/spec_helper.rb +16 -0
  150. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +15 -0
  151. data/spec/support/database_connection.rb +4 -0
  152. data/spec/support/database_models.rb +118 -0
  153. data/spec/support/octopus_helper.rb +55 -0
  154. data/spec/support/query_count.rb +17 -0
  155. data/spec/support/shared_contexts.rb +18 -0
  156. data/spec/tasks/octopus.rake_spec.rb +32 -0
  157. metadata +388 -0
@@ -0,0 +1,118 @@
1
+ document.observe("dom:loaded", function() {
2
+ function handleRemote(element) {
3
+ var method, url, params;
4
+
5
+ if (element.tagName.toLowerCase() === 'form') {
6
+ method = element.readAttribute('method') || 'post';
7
+ url = element.readAttribute('action');
8
+ params = element.serialize(true);
9
+ } else {
10
+ method = element.readAttribute('data-method') || 'get';
11
+ url = element.readAttribute('href');
12
+ params = {};
13
+ }
14
+
15
+ var event = element.fire("ajax:before");
16
+ if (event.stopped) return false;
17
+
18
+ new Ajax.Request(url, {
19
+ method: method,
20
+ parameters: params,
21
+ asynchronous: true,
22
+ evalScripts: true,
23
+
24
+ onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
25
+ onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
26
+ onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
27
+ onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
28
+ onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
29
+ onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
30
+ });
31
+
32
+ element.fire("ajax:after");
33
+ }
34
+
35
+ function handleMethod(element) {
36
+ var method, url, token_name, token;
37
+
38
+ method = element.readAttribute('data-method');
39
+ url = element.readAttribute('href');
40
+ csrf_param = $$('meta[name=csrf-param]').first();
41
+ csrf_token = $$('meta[name=csrf-token]').first();
42
+
43
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
44
+ element.parentNode.appendChild(form);
45
+
46
+ if (method != 'post') {
47
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
48
+ form.appendChild(field);
49
+ }
50
+
51
+ if (csrf_param) {
52
+ var param = csrf_param.readAttribute('content');
53
+ var token = csrf_token.readAttribute('content');
54
+ var field = new Element('input', { type: 'hidden', name: param, value: token });
55
+ form.appendChild(field);
56
+ }
57
+
58
+ form.submit();
59
+ }
60
+
61
+ $(document.body).observe("click", function(event) {
62
+ var message = event.findElement().readAttribute('data-confirm');
63
+ if (message && !confirm(message)) {
64
+ event.stop();
65
+ return false;
66
+ }
67
+
68
+ var element = event.findElement("a[data-remote]");
69
+ if (element) {
70
+ handleRemote(element);
71
+ event.stop();
72
+ return true;
73
+ }
74
+
75
+ var element = event.findElement("a[data-method]");
76
+ if (element) {
77
+ handleMethod(element);
78
+ event.stop();
79
+ return true;
80
+ }
81
+ });
82
+
83
+ // TODO: I don't think submit bubbles in IE
84
+ $(document.body).observe("submit", function(event) {
85
+ var element = event.findElement(),
86
+ message = element.readAttribute('data-confirm');
87
+ if (message && !confirm(message)) {
88
+ event.stop();
89
+ return false;
90
+ }
91
+
92
+ var inputs = element.select("input[type=submit][data-disable-with]");
93
+ inputs.each(function(input) {
94
+ input.disabled = true;
95
+ input.writeAttribute('data-original-value', input.value);
96
+ input.value = input.readAttribute('data-disable-with');
97
+ });
98
+
99
+ var element = event.findElement("form[data-remote]");
100
+ if (element) {
101
+ handleRemote(element);
102
+ event.stop();
103
+ }
104
+ });
105
+
106
+ $(document.body).observe("ajax:after", function(event) {
107
+ var element = event.findElement();
108
+
109
+ if (element.tagName.toLowerCase() === 'form') {
110
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
111
+ inputs.each(function(input) {
112
+ input.value = input.readAttribute('data-original-value');
113
+ input.writeAttribute('data-original-value', null);
114
+ input.disabled = false;
115
+ });
116
+ }
117
+ });
118
+ });
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
File without changes
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
+ if vendored_cucumber_bin
5
+ load File.expand_path(vendored_cucumber_bin)
6
+ else
7
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
8
+ require 'cucumber'
9
+ load Cucumber::BINARY
10
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Item do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe User do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,27 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path('../../config/environment', __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ # == Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+ config.mock_with :rspec
20
+
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, comment the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,217 @@
1
+ mysql: &mysql
2
+ adapter: mysql2
3
+ username: <%= ENV['MYSQL_USER'] || 'root' %>
4
+ host: localhost
5
+
6
+ mysql_unavailable: &mysql_unavailable
7
+ adapter: mysql2
8
+ username: <%= ENV['MYSQL_USER'] || 'root' %>
9
+ host: 192.0.2.1
10
+ connect_timeout: 3
11
+
12
+ octopus: &octopus
13
+ shards:
14
+ alone_shard:
15
+ database: octopus_shard_5
16
+ <<: *mysql
17
+
18
+ postgresql_shard:
19
+ adapter: postgresql
20
+ username: <%= ENV['POSTGRES_USER'] || 'postgres' %>
21
+ password:
22
+ database: octopus_shard_1
23
+ encoding: unicode
24
+ host: localhost
25
+
26
+ sqlite_shard:
27
+ adapter: sqlite3
28
+ database: /tmp/database.sqlite3
29
+
30
+ history_shards:
31
+ aug2009:
32
+ database: octopus_shard_2
33
+ <<: *mysql
34
+ aug2010:
35
+ database: octopus_shard_3
36
+ <<: *mysql
37
+ aug2011:
38
+ database: octopus_shard_4
39
+ <<: *mysql
40
+
41
+ country_shards:
42
+ canada:
43
+ database: octopus_shard_2
44
+ <<: *mysql
45
+ brazil:
46
+ database: octopus_shard_3
47
+ <<: *mysql
48
+ russia:
49
+ database: octopus_shard_4
50
+ <<: *mysql
51
+
52
+ protocol_shard: postgres://<%= ENV['POSTGRES_USER'] || 'postgres' %>@localhost:5432/octopus_shard_2
53
+
54
+ octopus_with_default_migration_group:
55
+ <<: *octopus
56
+ default_migration_group: country_shards
57
+
58
+ production_raise_error:
59
+ shards:
60
+ history_shards:
61
+ duplicated_shard_name:
62
+ database: octopus_shard_5
63
+ <<: *mysql
64
+
65
+ country_shards:
66
+ duplicated_shard_name:
67
+ database: octopus_shard_4
68
+ <<: *mysql
69
+
70
+ production_replicated:
71
+ replicated: true
72
+ fully_replicated: false
73
+
74
+ shards:
75
+ slave1:
76
+ database: octopus_shard_2
77
+ <<: *mysql
78
+ slave2:
79
+ database: octopus_shard_3
80
+ <<: *mysql
81
+ slave3:
82
+ database: octopus_shard_4
83
+ <<: *mysql
84
+ slave4:
85
+ database: octopus_shard_5
86
+ <<: *mysql
87
+
88
+
89
+ replicated_with_one_slave:
90
+ replicated: true
91
+ shards:
92
+ slave1:
93
+ database: octopus_shard_2
94
+ <<: *mysql
95
+
96
+ replicated_with_one_slave_unavailable:
97
+ replicated: true
98
+ shards:
99
+ slave1:
100
+ database: octopus_shard_2
101
+ <<: *mysql_unavailable
102
+
103
+
104
+ production_fully_replicated:
105
+ replicated: true
106
+ shards:
107
+ slave1:
108
+ database: octopus_shard_2
109
+ <<: *mysql
110
+ slave2:
111
+ database: octopus_shard_3
112
+ <<: *mysql
113
+ slave3:
114
+ database: octopus_shard_4
115
+ <<: *mysql
116
+ slave4:
117
+ database: octopus_shard_5
118
+ <<: *mysql
119
+
120
+ octopus_rails:
121
+ replicated: true
122
+ environments:
123
+ - staging
124
+ - production
125
+
126
+ staging:
127
+ slave1:
128
+ database: octopus_shard_2
129
+ <<: *mysql
130
+ slave2:
131
+ database: octopus_shard_3
132
+ <<: *mysql
133
+
134
+ production:
135
+ slave3:
136
+ database: octopus_shard_4
137
+ <<: *mysql
138
+ slave4:
139
+ database: octopus_shard_5
140
+ <<: *mysql
141
+
142
+ not_entire_sharded:
143
+ entire_sharded: false
144
+ shards:
145
+ europe:
146
+ database: octopus_shard_2
147
+ <<: *mysql
148
+ canada:
149
+ database: octopus_shard_3
150
+ <<: *mysql
151
+ brazil:
152
+ database: octopus_shard_4
153
+ <<: *mysql
154
+ russia:
155
+ database: octopus_shard_5
156
+ <<: *mysql
157
+
158
+ sharded_replicated_slave_grouped:
159
+ replicated: true
160
+ fully_replicated: true
161
+ shards:
162
+ russia:
163
+ database: octopus_shard_1
164
+ <<: *mysql
165
+ slaves1:
166
+ russia_slave11:
167
+ database: octopus_shard_1
168
+ <<: *mysql
169
+ russia_slave21:
170
+ database: octopus_shard_2
171
+ <<: *mysql
172
+ slaves2:
173
+ russia_slave21:
174
+ database: octopus_shard_3
175
+ <<: *mysql
176
+ russia_slave22:
177
+ database: octopus_shard_1
178
+ <<: *mysql
179
+ europe:
180
+ database: octopus_shard_2
181
+ <<: *mysql
182
+ slaves1:
183
+ europe_slave11:
184
+ database: octopus_shard_3
185
+ <<: *mysql
186
+ slaves2:
187
+ europe_slave21:
188
+ database: octopus_shard_1
189
+ <<: *mysql
190
+
191
+ replicated_slave_grouped:
192
+ replicated: true
193
+ fully_replicated: true
194
+ shards:
195
+ slaves1:
196
+ slave11:
197
+ database: octopus_shard_2
198
+ <<: *mysql
199
+ slaves2:
200
+ slave21:
201
+ database: octopus_shard_1
202
+ <<: *mysql
203
+ slaves3:
204
+ slave31:
205
+ database: octopus_shard_1
206
+ <<: *mysql
207
+ slave32:
208
+ database: octopus_shard_2
209
+ <<: *mysql
210
+
211
+ modify_config:
212
+ replicated: true
213
+ shards:
214
+ modify_config_read:
215
+ adapter: modify_config
216
+ database: octopus_shard_1
217
+ host: localhost
@@ -0,0 +1,9 @@
1
+ class CreateUsersUsingReplication < ActiveRecord::Migration
2
+ def self.up
3
+ Cat.create!(:name => 'Replication')
4
+ end
5
+
6
+ def self.down
7
+ Cat.delete_all
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class AddFieldInAllSlaves < ActiveRecord::Migration
2
+ using(:slave1, :slave2, :slave3, :slave4)
3
+
4
+ def self.up
5
+ Cat.create!(:name => 'Slaves')
6
+ end
7
+
8
+ def self.down
9
+ Cat.delete_all
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ class CreateUsersUsingBlock < ActiveRecord::Migration
2
+ def self.up
3
+ Octopus.using(:brazil) do
4
+ User.create!(:name => 'UsingBlock1')
5
+ User.create!(:name => 'UsingBlock2')
6
+ end
7
+
8
+ Octopus.using(:canada) do
9
+ User.create!(:name => 'UsingCanada')
10
+ User.create!(:name => 'UsingCanada2')
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ Octopus.using(:brazil) do
16
+ User.delete_all
17
+ end
18
+
19
+ Octopus.using(:canada) do
20
+ User.delete_all
21
+ end
22
+ end
23
+ end