多个 Rails 数据库 :tada:
:fire: Multiple databases for Rails
**ActiveRecord supports multiple databases, but Rails migrations_paths: db/catalog_migrate
development: primary: <<: *default database: ... catalog: <<: *catalog_default database: ...
test: primary: <<: *default database: ... catalog: <<: *catalog_default database: ...
production: primary: <<: *default database: ... catalog: <<: *catalog_default database: ...
Then change `establish_connection` in `app/models/catalog_record.rb` to:
```rb
class CatalogRecord < ActiveRecord::Base
establish_connection :catalog
endAnd move:
db/catalog/migrate to db/catalog_migratedb/catalog/schema.rb to db/catalog_schema.rb (or db/catalog/structure.sql to db/catalog_structure.sql).Then remove multiverse from your Gemfile. :tada:
Now you can use the updated commands:
rails db:migrate # run all
rails db:migrate:catalog # runs catalog onlyGenerate migrations with:
rails generate migration add_name_to_products --database=catalogAnd models with:
rails generate model Product --database=catalog --parent=CatalogRecordHappy scaling!
View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
To get started with development and testing:
git clone https://github.com/ankane/multiverse.git
cd multiverse
bundle install
bundle exec rake test暂无开放 Issues,或尚未同步最近议题。