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
错误。虽然这可能只适用于指定的碎片,但我希望迁移应用于所有碎片。