Cyril Duchon-Doris
Cyril Duchon-Doris

Reputation: 13949

Adding ActiveRecord on top of a Rails + Mongoid install

I have an existing project with Rails 5.2 and Mongoid 7, I had previously disabled all activerecord-related modules.

We are working on some synchronization with business intelligence data warehouses, and I discovered this gem that seems like a good starting point : I'm planning to use ActiveRecord with this adapter to easily implement code that will push data to my Amazon Aurora DB for BI purposes.

I have created a simple model

# model/test.rb
class Test < ActiveRecord::Base
end

I have added a database.yml

# config/database.yml
development:
  adapter: aurora_serverless
  ...

But when I try to do anything with a model it says it could not connect

ActiveRecord::ConnectionNotEstablished: No connection with pool with 'primary' found

Am I missing other things to make ActiveRecord work ? Do I need some additional Railties, etc ? It's as if the database.yml file was not read at all

Upvotes: 1

Views: 145

Answers (1)

Cyril Duchon-Doris
Cyril Duchon-Doris

Reputation: 13949

Here is a summary of the things I ended up doing

  • add required gems in your Gemfile (as a matter of fact, the gem I added did not even require the mysql2 gem which is quite a relief as mysql2 has dependencies on the local OS libs, and you're quite likely to encounter many bugs)

  • create a config/database.yml file, and have one key per environment you need, with the AR config you need

  • in application.rb, add require 'active_record/railtie' (the railtie will initialize connection from the database.yml file)

  • create some models

  • Maybe you need extra adapters for local/test/staging/prod environments

  • Add a container for a SQL DB if you're working with docker-compose

Upvotes: 0

Related Questions