Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating sample application

  • Loading branch information...
commit 7cb524f83afd89e9bf19112ff7c191f6aad22077 1 parent aeb2fc8
@tchandy authored
View
2  Gemfile
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
gem 'rails', '3.0.0.beta4'
gem 'mysql', '2.8.1'
-gem 'ar-octopus', '0.0.19', :require => "octopus"
+gem 'ar-octopus', :git => "git://github.com/tchandy/octopus.git", :require => "octopus"
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
266 Gemfile.lock
@@ -0,0 +1,266 @@
+GIT
+ remote: git://github.com/tchandy/octopus.git
+ revision: eb8cfcd
+ specs:
+ ar-octopus (0.0.22)
+ activerecord (>= 3.0.0beta)
+ ar-octopus (0.0.22)
+ activerecord (>= 3.0.0beta)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ abstract (1.0.0)
+ actionmailer (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ mail (~> 2.2.3)
+ actionmailer (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ mail (~> 2.2.3)
+ actionpack (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.5)
+ i18n (~> 0.4.1)
+ rack (~> 1.1.0)
+ rack-mount (~> 0.6.3)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.16)
+ actionpack (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.5)
+ i18n (~> 0.4.1)
+ rack (~> 1.1.0)
+ rack-mount (~> 0.6.3)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.16)
+ activemodel (3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activemodel (3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.16)
+ activerecord (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.16)
+ activeresource (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ activeresource (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ activesupport (3.0.0.beta4)
+ activesupport (3.0.0.beta4)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ builder (2.1.2)
+ builder (2.1.2)
+ capybara (0.3.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.3)
+ capybara (0.3.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.3)
+ columnize (0.3.1)
+ columnize (0.3.1)
+ configuration (1.1.0)
+ configuration (1.1.0)
+ cucumber (0.8.3)
+ builder (~> 2.1.2)
+ diff-lcs (~> 1.1.2)
+ gherkin (~> 2.0.2)
+ json_pure (~> 1.4.3)
+ term-ansicolor (~> 1.0.4)
+ cucumber (0.8.3)
+ builder (~> 2.1.2)
+ diff-lcs (~> 1.1.2)
+ gherkin (~> 2.0.2)
+ json_pure (~> 1.4.3)
+ term-ansicolor (~> 1.0.4)
+ cucumber-rails (0.3.2)
+ cucumber (>= 0.8.0)
+ cucumber-rails (0.3.2)
+ cucumber (>= 0.8.0)
+ culerity (0.2.10)
+ culerity (0.2.10)
+ database_cleaner (0.5.2)
+ database_cleaner (0.5.2)
+ diff-lcs (1.1.2)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ gherkin (2.0.2)
+ trollop (~> 1.16.2)
+ gherkin (2.0.2)
+ trollop (~> 1.16.2)
+ i18n (0.4.1)
+ i18n (0.4.1)
+ json_pure (1.4.3)
+ json_pure (1.4.3)
+ launchy (0.3.5)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
+ launchy (0.3.5)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
+ linecache (0.43)
+ linecache (0.43)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ mime-types (1.16)
+ mysql (2.8.1)
+ mysql (2.8.1)
+ nokogiri (1.4.2)
+ nokogiri (1.4.2)
+ polyglot (0.3.1)
+ polyglot (0.3.1)
+ rack (1.1.0)
+ rack (1.1.0)
+ rack-mount (0.6.7)
+ rack
+ rack-mount (0.6.7)
+ rack
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rails (3.0.0.beta4)
+ actionmailer (= 3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activerecord (= 3.0.0.beta4)
+ activeresource (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ bundler (>= 0.9.26)
+ railties (= 3.0.0.beta4)
+ rails (3.0.0.beta4)
+ actionmailer (= 3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activerecord (= 3.0.0.beta4)
+ activeresource (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ bundler (>= 0.9.26)
+ railties (= 3.0.0.beta4)
+ railties (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ rake (>= 0.8.3)
+ thor (~> 0.13.6)
+ railties (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ rake (>= 0.8.3)
+ thor (~> 0.13.6)
+ rake (0.8.7)
+ rake (0.8.7)
+ rspec (2.0.0.beta.17)
+ rspec-core (= 2.0.0.beta.17)
+ rspec-expectations (= 2.0.0.beta.17)
+ rspec-mocks (= 2.0.0.beta.17)
+ rspec (2.0.0.beta.17)
+ rspec-core (= 2.0.0.beta.17)
+ rspec-expectations (= 2.0.0.beta.17)
+ rspec-mocks (= 2.0.0.beta.17)
+ rspec-core (2.0.0.beta.17)
+ rspec-core (2.0.0.beta.17)
+ rspec-expectations (2.0.0.beta.17)
+ diff-lcs (>= 1.1.2)
+ rspec-expectations (2.0.0.beta.17)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.17)
+ rspec-mocks (2.0.0.beta.17)
+ rspec-rails (2.0.0.beta.17)
+ rspec (>= 2.0.0.beta.14)
+ webrat (>= 0.7.0)
+ rspec-rails (2.0.0.beta.17)
+ rspec (>= 2.0.0.beta.14)
+ webrat (>= 0.7.0)
+ ruby-debug (0.10.3)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.3.0)
+ ruby-debug (0.10.3)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.3.0)
+ ruby-debug-base (0.10.3)
+ linecache (>= 0.3)
+ ruby-debug-base (0.10.3)
+ linecache (>= 0.3)
+ selenium-webdriver (0.0.24)
+ ffi (>= 0.6.1)
+ json_pure
+ selenium-webdriver (0.0.24)
+ ffi (>= 0.6.1)
+ json_pure
+ spork (0.8.4)
+ spork (0.8.4)
+ term-ansicolor (1.0.5)
+ term-ansicolor (1.0.5)
+ thor (0.13.7)
+ thor (0.13.7)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ trollop (1.16.2)
+ trollop (1.16.2)
+ tzinfo (0.3.22)
+ tzinfo (0.3.22)
+ webrat (0.7.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
+ webrat (0.7.1)
+ nokogiri (>= 1.2.0)
+ rack (>= 1.0)
+ rack-test (>= 0.5.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ ar-octopus!
+ capybara
+ cucumber
+ cucumber-rails
+ database_cleaner
+ launchy
+ mysql (= 2.8.1)
+ rails (= 3.0.0.beta4)
+ rspec-rails (>= 2.0.0.beta)
+ ruby-debug
+ spork
View
46 README.mkdn
@@ -6,49 +6,9 @@
<p> All writes will be sent to master, and the read queries will be sent to the slaves. unless you have a transaction, so , all queries will be sent to master.</p>
-<h2> How-to </h2>
-<p>Octopus is simple to use, just follow the steps:</p>
-- Add the gem to your Gemfile:
-
-<pre>gem 'ar-octopus', '0.0.12', :require => "octopus"</pre>
-
-- Create a shards.yml file inside config directory, that looks like this:
-
-<pre>
-development:
- replicated: true
- shards:
- slave1:
- adapter: mysql
- host: localhost
- database: octopus_replication_2
- slave2:
- adapter: mysql
- host: localhost
- database: octopus_replication_3
- slave3:
- adapter: mysql
- host: localhost
- database: octopus_replication_4
- slave4:
- adapter: mysql
- host: localhost
- database: octopus_replication_5
-</pre>
-
-<p> First, you need to specify what enviroment will have the slaves. After this, the line replicated means that you have replicated databases. Above this, you need to specify the name and the address of your slaves.</p>
-<p>If you want all models of your application to be replicated, add the following line to shards.yml:</p>
-
-<pre>entire_replicated: true</pre>
-
-<p> If your application isn't have all models replicated (like this example), you need to specify each replicated model with this line:</p>
-
-<pre>
-class User < ActiveRecord::Base
- replicated_model
-end
-</pre>
-
+<h2> Setup: </h2>
+<p> You will need two commands to setup the application:</p>
+<pre> rake db:octopus && rake db:migrate </pre>
<p>More info could be found at <a href="http://wiki.github.com/tchandy/octopus/">Octopus Wiki</a> </p>
View
38 config/shards.yml
@@ -1,19 +1,23 @@
octopus:
replicated: true
- shards:
- slave1:
- adapter: mysql
- host: localhost
- database: octopus_replication_2
- slave2:
- adapter: mysql
- host: localhost
- database: octopus_replication_3
- slave3:
- adapter: mysql
- host: localhost
- database: octopus_replication_4
- slave4:
- adapter: mysql
- host: localhost
- database: octopus_replication_5
+ octopus_enviroments:
+ - development
+ - production
+ development:
+ shards:
+ slave1:
+ adapter: mysql
+ host: localhost
+ database: octopus_replication_2
+ slave2:
+ adapter: mysql
+ host: localhost
+ database: octopus_replication_3
+ slave3:
+ adapter: mysql
+ host: localhost
+ database: octopus_replication_4
+ slave4:
+ adapter: mysql
+ host: localhost
+ database: octopus_replication_5
View
9 db/schema.rb
@@ -8,20 +8,21 @@
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
+
ActiveRecord::Schema.define(:version => 20100623041305) do
- create_table "clients", :id => false, :force => true do |t|
- t.integer "id", :null => false
+
+ create_table "clients", :force => true do |t|
t.string "name"
t.date "birthday"
t.datetime "created_at"
t.datetime "updated_at"
end
- create_table "users", :id => false, :force => true do |t|
- t.integer "id", :null => false
+ create_table "users", :force => true do |t|
t.string "name"
t.date "birthday"
t.datetime "created_at"
t.datetime "updated_at"
end
+
end
View
15 lib/tasks/setup.rake
@@ -4,7 +4,7 @@ namespace :db do
task :build_databases do
mysql_user = ENV['MYSQL_USER'] || "root"
- (1..4).each do |idx|
+ (1..5).each do |idx|
%x( echo "create DATABASE octopus_replication_#{idx} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{mysql_user})
end
end
@@ -13,22 +13,13 @@ namespace :db do
task :drop_databases do
mysql_user = ENV['MYSQL_USER'] || "root"
- (1..4).each do |idx|
+ (1..5).each do |idx|
%x( mysqladmin --user=#{mysql_user} -f drop octopus_replication_#{idx} )
end
end
-
- desc 'Create tables on tests databases'
- task :create_tables do
- [:slave1, :slave2, :slave3, :slave4].each do |shard_symbol|
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:schema_migrations) do |u|
- u.string :version, :unique => true, :null => false
- end
- end
- end
desc 'Prepare the test databases'
- task :prepare => [:drop_databases, :build_databases, :create_tables]
+ task :octopus => [:drop_databases, :build_databases]
end
Please sign in to comment.
Something went wrong with that request. Please try again.