thiagopradi / octopus

Database Sharding for ActiveRecord
2.53k stars 505 forks source link

always return data from master db #470

Open andyhu1007 opened 6 years ago

andyhu1007 commented 6 years ago

activerecord (4.1.8) ar-octopus (0.9.1) mysql2 (0.3.21)

database.yml

shared: &shared
  host: localhost
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: tao
  password: password
  socket: /tmp/mysql.sock

development:
  <<: *shared
  database: tao_development

test:
  <<: *shared
  database: tao_test

shards.yml

octopus:
  environments:
    - development
    - test
  development:
    users2:
      host: localhost
      adapter: mysql2
      encoding: utf8
      pool: 5
      username: tao
      password: password
      socket: /tmp/mysql2.sock
      database: tao_development2
  test:
    users2:
      adapter: mysql2
      database: tao_test2

Rails console code:

User.using(:users2).connection

u =User.using(:users2).first

u.current_shard
   => :users2

User.using(:users2).connection.class
   => ActiveRecord::ConnectionAdapters::Mysql2Adapter

but it does not return data in shards db, but from master.

anything wrong with my configuration?

nienko commented 5 years ago

Same for me with:

Rails 4.0.13 ar-octopus (0.9.2) pg (0.18.4)