There is one very large project (about 100 tables) on Rails 5.1.2. And he is texting.
It is being rewritten from scratch, a new DB architecture, new models, connections, etc. are being designed. But in the end this is all the same project, the data in the new version will essentially be the same.
In the course of the implementation of new sections in the project will need to fill in the relevant (section) tables.
I took all the models from the old project and put them in the new models/old directory. And for starters, in application_record.rb and post.rb , Old:: added to the class names.
Back in database.yml I added new data (from the second database) and in the application_record.rb added the string establish_connection 'development_old' .
The result was this:
class Old::ApplicationRecord < ActiveRecord::Base establish_connection 'development_old' self.abstract_class = true end And one test model:
class Old::Post < Old::ApplicationRecord # ... end Well, database.yml for the full picture:
development_old: adapter: postgresql encoding: unicode pool: 10 host: 11.22.33.44 port: 5432 database: 111 username: 222 password: 333 As a result, I register rails c -e development in the console, then: Old::Post.all and get:
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter from app/models/old/application_record.rb:2:in `<class:ApplicationRecord>' from app/models/old/application_record.rb:1:in `<top (required)>' from app/models/old/post.rb:1:in `<top (required)>' from (irb):1 What have I done wrong?