Skip to content

Rails 7 - Database configuration does not specify adapter  #47

@leoplct

Description

@leoplct

I am using Ruby on Rails 7 with multiple databases. I got this error.

  1. I tried with:adapter: net_http but it isn't recognized.
  2. Removing this line it doesn't raise exception but it doesn't connect to the secondary database.
    How do I say to connect to the secondary database (ams) instead of primary ?

app/models/ams_record.rb
connects_to database: { writing: :ams, reading: :ams }

/Users/name/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_handler.rb:261:in `resolve_pool_config':

database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)

database.yml

default_ams: &default_ams
  timeout: 60
  open_timeout: 3

development:
  primary:
    <<: *default
    database: xxx_development
    password: password
    host: localhost
    port: 5432
  ams:
    <<: *default_ams
    database: ams_development
    username: default
    password: XXXX
    url: https://xxx.us-east-1.aws.clickhouse.cloud:8443

app/models/click_house_record.rb

class ClickHouseRecord < ActiveRecord::Base
  self.abstract_class = true

  class << self
    def agent
      ClickHouse.connection
    end

    def insert(*argv, &block)
      agent.insert(table_name, *argv, &block)
    end

    def select_one
      agent.select_one(current_scope.to_sql)
    end

    def select_value
      agent.select_value(current_scope.to_sql)
    end

    def select_all
      agent.select_all(current_scope.to_sql)
    end

    def explain
      agent.explain(current_scope.to_sql)
    end
  end
end

app/models/ams_record.rb

class AmsRecord < ClickHouseRecord
  self.abstract_class = true

  connects_to database: { writing: :ams, reading: :ams }

end

app/models/ams_traffic.rb

class AmsTraffic < AmsRecord
   # This is my table on Click House
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions