# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem "sqlite3"
#
default: &default
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 50 } %>
  timeout: 5000

development:
  primary:
    <<: *default
    adapter: postgresql
    encoding: unicode
    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
    url: <%= ENV['DATABASE_URL'] %>
  primary_direct:
    url: <%= ENV['DATABASE_URL'] %>
    adapter: postgresql
    encoding: unicode
    database_tasks: false
  wakatime:
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['WAKATIME_DATABASE_URL'] %>
    replica: true
  sailors_log:
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['SAILORS_LOG_DATABASE_URL'] %>
    replica: true
  warehouse:
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['WAREHOUSE_DATABASE_URL'] %>
    replica: true

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  primary:
    <<: *default
    adapter: postgresql
    database: test_db
    username: postgres
    password: postgres
    # url: <%= ENV['TEST_DATABASE_URL'] %>
  primary_direct:
    adapter: postgresql
    database: test_db
    username: postgres
    password: postgres
    database_tasks: false
  wakatime:
    adapter: postgresql
    database: test_wakatime
    username: postgres
    password: postgres
    replica: true
  sailors_log:
    adapter: postgresql
    database: test_sailors_log
    username: postgres
    password: postgres
    replica: true
  warehouse:
    adapter: postgresql
    database: test_warehouse
    username: postgres
    password: postgres
    replica: true

# Store production database in the storage/ directory, which by default
# is mounted as a persistent Docker volume in config/deploy.yml.
production:
  primary:
    <<: *default
    adapter: postgresql
    encoding: unicode
    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 16 }.to_i + 8 %> # Web threads + 8 GoodJob threads
    url: <%= ENV['POOL_DATABASE_URL'] %>
  primary_direct: # https://github.com/bensheldon/good_job?tab=readme-ov-file#pgbouncer-compatibility
    url: <%= ENV['DATABASE_URL'] %>
    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 16 }.to_i + 8 %> # Web threads + 8 GoodJob threads
    adapter: postgresql
    encoding: unicode
    database_tasks: false
  wakatime:
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['WAKATIME_DATABASE_URL'] %>
    replica: true
  sailors_log:
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['SAILORS_LOG_DATABASE_URL'] %>
    replica: true
  warehouse:
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['WAREHOUSE_DATABASE_URL'] %>
    replica: true
  cache:
    <<: *default
    adapter: postgresql
    encoding: unicode
    url: <%= ENV['DATABASE_URL'] %>
  cable:
    <<: *default
    adapter: sqlite3
    database: storage/production_cable.sqlite3
    migrations_paths: db/cable_migrate
