开发者

Rails - generating .sqlite3-databases

开发者 https://www.devze.com 2023-01-04 16:27 出处:网络
My rails app. uses mysql database and I need to generate .sqlite3.databases. Is it possible to use activerecord and rails models for it?

My rails app. uses mysql database and I need to generate .sqlite3.databases. Is it possible to use activerecord and rails models for it? We are trying now to use models namespaced by Re开发者_如何学Pythonmote:: module but by this way we can't start concurrent generators.


In your remote models, you want to connect to a separate database using #establish_connection:

# config/database.yml
remote_development:
  adapter: sqlite3
  database: db/development.sqlite3

remote_production:
  adapter: sqlite3
  database: /usr/local/remote/myapp.sqlite3


# app/models/remote_model.rb
class RemoteModel < ActiveRecord::Base
  establish_connection "remote_#{Rails.env}"
  self.abstract_class = true
end


# app/models/remote_user.rb
class RemoteUser < RemoteModel
end

Note the abstract_class setter: this means the class in question doesn't have an underlying table: it's used for configuration purposes only.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号