active_record.cr icon indicating copy to clipboard operation
active_record.cr copied to clipboard

Adapter configuration

Open sdogruyol opened this issue 10 years ago • 6 comments

We need to have a way to configure the underlying adapter. This is needed for

  • Setting connection url, user, password, host e.g
  • Timeout options
  • Pool options

WDYT @waterlink

sdogruyol avatar Nov 05 '15 13:11 sdogruyol

Yeah of course! I expect this list to be waaay longer in the future :)

I would love to have similar configuration to the ruby's AR - through config/database.yml or something.

Though it would be nice to leave an option for 12factor. I.e.: there should be still a possibility to configure everything through environment variables, that are in certain format.

For example, given this config/database.yml file:

override_prefix: MYAPP

adapters:
  postgres:
    username: john
    password: welcome
    hostname: 127.0.0.1
    port: 5432
    timeout: 5000     # ms
    pool: 10

You can for example override hostname with: export MYAPP_ADAPTERS_POSTGRES_HOSTNAME=db.production01.internal.myapp.com and so on.

alex-fedorov avatar Nov 05 '15 19:11 alex-fedorov

Implementation for this should probably sit within active_record.cr codebase. And it should expose some simple integration API for querying, along the lines:

ActiveRecord::Config.adapters.postgres.encoding? || "utf8"

alex-fedorov avatar Nov 05 '15 19:11 alex-fedorov

maybe config file name can be more specific: config/active_record.yml

alex-fedorov avatar Nov 05 '15 19:11 alex-fedorov

Maybe it would be nice to junk in different environments:

override_prefix: MYAPP

environments:
  development:
    adapters:
      postgres:
        # ...

alex-fedorov avatar Nov 05 '15 19:11 alex-fedorov

Or maybe just have different names for files, like Elixir does:

  • config/active_record.yml - default config
  • config/development/active_record.yml - development config
  • config/test/active_record.yml - test config
  • config/production/active_record.yml - production config

alex-fedorov avatar Nov 05 '15 19:11 alex-fedorov

I prefer the AR style

sdogruyol avatar Nov 05 '15 19:11 sdogruyol