Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails with Octopus gem. How to create db's defined in shards.yml with rake

I need to configure my app to use multiple shards, and even multiple db adapters. I have noticed that all rake commands like rake db:migrate are working, and have consequence on shards defined in shards.yml, except rake db:create. It will be a real pain to create all this manually. How can I make it work?

My database.yml (I have defined here, only my master shard)

development:
  adapter:  postgresql
  host:     localhost
  encoding: unicode
  database: db_workload_master_development
  pool:     5
  username: 
  password: 

production:
  ...... 

My shards.yml

octopus:
  environments:
    - production
    - development
  development:
    shards:
      mysql:
        host: localhost
        adapter: mysql2
        database: db_workload_mysql_shard_development
      sqlite:
        host: localhost
        adapter: sqlite3
        database: db_workload_sqlite_shard_development
      pg:
        host: localhost
        adapter: postgresql
        database: db_workload_pg_shard_development
        pool:     5
        username: 
        password: 
  production:
    ....

Only db's from database.yml are created with rake-task rake db:create.

like image 396
Andrey Yasinishyn Avatar asked Nov 24 '22 03:11

Andrey Yasinishyn


1 Answers

I would recommend creating your own rake task that will read the shards.yml and create the db's as appropriate.

like image 128
omarvelous Avatar answered Apr 27 '23 06:04

omarvelous