Created
January 18, 2016 13:23
-
-
Save nowlinuxing/b3a0455a3c7afc97f0d9 to your computer and use it in GitHub Desktop.
Use octopus with a master DB with some slaves, and sharded some user DBs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# class CreateCompanies < ActiveRecord::Migration | |
# def change | |
# create_table :companies do |t| | |
# t.string :name | |
# | |
# t.timestamps null: false | |
# end | |
# end | |
# end | |
class Company < ActiveRecord::Base | |
replicated_model() | |
end | |
# > Company.count | |
# (0.6ms) SELECT COUNT(*) FROM "cards" | |
# => 0 | |
# > Company.using(slave_group: :master_slaves).count | |
# [Shard: master01] (0.9ms) SELECT COUNT(*) FROM "companies" | |
# => 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: &default | |
adapter: sqlite3 | |
pool: 5 | |
timeout: 5000 | |
octopus: | |
replicated: true | |
fully_replicated: false | |
environments: | |
- development | |
development: | |
master_slaves: | |
master01: | |
<<: *default | |
database: db/development_master01.sqlite3 | |
master02: | |
<<: *default | |
database: db/development_master02.sqlite3 | |
user_shards: | |
user01: | |
<<: *default | |
database: db/development_user01.sqlite3 | |
user02: | |
<<: *default | |
database: db/development_user02.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# class CreateUsers < ActiveRecord::Migration | |
# using_group(:user_shards) | |
# | |
# def change | |
# create_table :users do |t| | |
# t.string :name | |
# | |
# t.timestamps null: false | |
# end | |
# end | |
# end | |
class User < ActiveRecord::Base | |
end | |
# > User.count | |
# ActiveRecord::StatementInvalid: Could not find table 'users' | |
# from /Users/user/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:511:in `table_structure' | |
# > User.using(:user01).count | |
# [Shard: user01] (0.6ms) SELECT COUNT(*) FROM "users" | |
# => 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment