# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'

default: &default
  adapter: sqlite3
  pool: <%= 
    if ENV["DATABASE_POOL_SIZE"].present?
      ENV["DATABASE_POOL_SIZE"]
    else
      # Calculate based on max threads and estimated workers
      # Default to threads*workers or at least 5 connections
      max_threads = ENV.fetch("RAILS_MAX_THREADS", 12).to_i
      workers = ENV.fetch("WEB_CONCURRENCY", 2).to_i
      [max_threads * workers, 5].max
    end
  %>
  timeout: 5000

development:
  primary:
    <<: *default
    database: db/development.sqlite3
    migrations_paths: db/migrate
  queue:
    <<: *default
    database: db/development-queue.sqlite3
    migrations_paths: db/queue/migrate
  cache:
    <<: *default
    database: db/development-cache.sqlite3
    migrations_paths: db/cache/migrate
  cable:
    <<: *default
    database: db/development-cable.sqlite3
    migrations_paths: db/cable/migrate

# 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
    database: db/test.sqlite3
    migrations_paths: db/migrate
  queue:
    <<: *default
    database: db/test-queue.sqlite3
    migrations_paths: db/queue/migrate
  cache:
    <<: *default
    database: db/test-cache.sqlite3
    migrations_paths: db/cache/migrate
  cable:
    <<: *default
    database: db/test-cable.sqlite3
    migrations_paths: db/cable/migrate

production:
  primary:
    adapter: mysql2
    encoding: utf8
    database: <%= ENV['WRESTLINGDEV_DB_NAME'] %>
    username: <%= ENV['WRESTLINGDEV_DB_USR'] %>
    password: <%= ENV['WRESTLINGDEV_DB_PWD'] %>
    host: <%= ENV['WRESTLINGDEV_DB_HOST'] %>
    port: <%= ENV['WRESTLINGDEV_DB_PORT'] %>
    migrations_paths: db/migrate
  queue:
    adapter: mysql2
    encoding: utf8
    database: <%= ENV['WRESTLINGDEV_DB_NAME'] %>-queue
    username: <%= ENV['WRESTLINGDEV_DB_USR'] %>
    password: <%= ENV['WRESTLINGDEV_DB_PWD'] %>
    host: <%= ENV['WRESTLINGDEV_DB_HOST'] %>
    port: <%= ENV['WRESTLINGDEV_DB_PORT'] %>
    migrations_paths: db/queue/migrate
  cache:
    adapter: mysql2
    encoding: utf8
    database: <%= ENV['WRESTLINGDEV_DB_NAME'] %>-cache
    username: <%= ENV['WRESTLINGDEV_DB_USR'] %>
    password: <%= ENV['WRESTLINGDEV_DB_PWD'] %>
    host: <%= ENV['WRESTLINGDEV_DB_HOST'] %>
    port: <%= ENV['WRESTLINGDEV_DB_PORT'] %>
    migrations_paths: db/cache/migrate
  cable:
    adapter: mysql2
    encoding: utf8
    database: <%= ENV['WRESTLINGDEV_DB_NAME'] %>-cable
    username: <%= ENV['WRESTLINGDEV_DB_USR'] %>
    password: <%= ENV['WRESTLINGDEV_DB_PWD'] %>
    host: <%= ENV['WRESTLINGDEV_DB_HOST'] %>
    port: <%= ENV['WRESTLINGDEV_DB_PORT'] %>
    migrations_paths: db/cable/migrate

