accessing shards from shard groups

14 views
Skip to first unread message

Jeff Rossi

unread,
Nov 17, 2017, 10:57:23 AM11/17/17
to Octopus - Database sharding for ActiveRecord
given the following pseudo config

octopus:
  environments:
    - development

  development:
    shards:
      new_api_shards:
        alpha:
          adapter: mysql2
          database: new_api_development
          username: root
          password: secret
          host: localhost
        beta:
          adapter: mysql2
          database: new_api_development_beta
          username: root
          password: secret
          host: localhost
      legacy_shards:
        alpha:
          adapter: mysql2
          database: legacy_development
          username: root
          password: secret
          host: localhost
        beta:
          adapter: mysql2
          database: legacy_development_beta
          username: root
          password: secret
          host: localhost


what using would I need to use in order to run queries on legacy_shards -> beta

Thiago Pradi

unread,
Nov 19, 2017, 8:20:36 PM11/19/17
to octopus-ac...@googlegroups.com
Hi Jeff,

To run queries on the legacy_shards -> beta, first, you need to change the name if your shard - you can't have duplicate shard names in different groups. Shard names must be unique.

To run the queries, you can simply use the following code: 

Octopus.using(:beta) do   
   User.create!(name: "Thiago") 
 end

Best Regards,

Thiago 

--
You received this message because you are subscribed to the Google Groups "Octopus - Database sharding for ActiveRecord" group.
To unsubscribe from this group and stop receiving emails from it, send an email to octopus-activerecord+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Jeff Rossi

unread,
Nov 20, 2017, 8:13:35 AM11/20/17
to Octopus - Database sharding for ActiveRecord
Thanks,

does the documentation indicate that shard names need to be unique? I don't recall, in the middle of an application rewrite.

Thiago Pradi

unread,
Nov 20, 2017, 8:17:05 AM11/20/17
to octopus-ac...@googlegroups.com
Hi Jeff,

I don't think so. I think it might be a good improvement to our README. Feel free to send a PR updating the docs - I'll review and merge it.

Thanks,

Thiago

--
You received this message because you are subscribed to the Google Groups "Octopus - Database sharding for ActiveRecord" group.
To unsubscribe from this group and stop receiving emails from it, send an email to octopus-activerecord+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages