Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 7 - Database configuration does not specify adapter #47

Open
leoplct opened this issue Nov 11, 2023 · 0 comments
Open

Rails 7 - Database configuration does not specify adapter #47

leoplct opened this issue Nov 11, 2023 · 0 comments

Comments

@leoplct
Copy link

leoplct commented Nov 11, 2023

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
@leoplct leoplct changed the title database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) Rails 7 - database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) Nov 11, 2023
@leoplct leoplct changed the title Rails 7 - database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) Rails 7 - Database configuration does not specify adapter Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant