Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails上一次迁移多个不是主从关系的碎片?_Ruby On Rails_Sharding_Octopus - Fatal编程技术网

Ruby on rails 如何在rails上一次迁移多个不是主从关系的碎片?

Ruby on rails 如何在rails上一次迁移多个不是主从关系的碎片?,ruby-on-rails,sharding,octopus,Ruby On Rails,Sharding,Octopus,我有一个应用程序,它根据子域使用不同的数据库。因此,基本上,模式是相同的,但是每个数据库的数据都不同。但是当我发布一些新特性并且需要一些模式更改时,我需要运行一个命令,该命令将在shards.yml中配置的所有数据库上运行 数据库.yml default: &default adapter: postgresql encoding: unicode pool: 15 host: localhost port: 5432 username: postgres p

我有一个应用程序,它根据子域使用不同的数据库。因此,基本上,模式是相同的,但是每个数据库的数据都不同。但是当我发布一些新特性并且需要一些模式更改时,我需要运行一个命令,该命令将在
shards.yml
中配置的所有数据库上运行

数据库.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 15
  host: localhost
  port: 5432
  username: postgres
  password:

development:
  <<: *default
  database: app_default
production:
  <<: *default
  database: app_default
  username: <%= ENV['BACKEND_DATABASE_USERNAME'] %>
  password: <%= ENV['BACKEND_DATABASE_PASSWORD'] %>
shared: &shared
  adapter: postgresql
  encoding: unicode
  pool: 15
  host: localhost
  username: postgres
  password: 
  port: 5432

octopus:
  environments:
    - development
    - test
    - production
  development:
    default:
      <<: *shared
      database: app
    first:
      <<: *shared
      database: first
    second:
      <<: *shared
      database: second
    ....
  test:
    test:
      host: postgres
      adapter: postgresql
      database: app_test
  production:
    default:
      <<: *shared
      database: app
    first:
      <<: *shared
      database: first
    second:
      <<: *shared
      database: second
    ....
default:&default
适配器:postgresql
编码:unicode
游泳池:15
主机:本地主机
港口:5432
用户名:postgres
密码:
发展:

您必须使用
添加到迁移中

class CreateComments < ActiveRecord::Migration
  using :first, :second

  def change
    create_table :comments do |t|
      t.belongs_to :page, index: true
      t.text :body

      t.timestamps
    end
  end
end
class CreateComments

上述迁移将在
第一次
第二次

上运行,感谢您花时间回答这个问题。不幸的是,此解决方案仍然无法解决
railsdb:reset
错误。虽然这可能只适用于指定的碎片,但我希望迁移应用于所有碎片。