Module: Inferno::Config::Boot::Db

Defined in:
lib/inferno/config/boot/db.rb

Overview

Extracted from the :db provider below so the sqlite-only branching can be unit tested with plain config hashes/doubles, instead of requiring a real postgres connection (which this project has no infrastructure for) just to exercise the non-sqlite path.

Class Method Summary collapse

Class Method Details

.configure_sqlite_pragmas!(config) ⇒ Object

The web and worker processes each hold their own pool of connections to the same sqlite file, so writes from one process can easily collide with reads or writes from another. WAL mode lets readers proceed without blocking on a concurrent writer, and a longer busy_timeout gives a blocked writer more room to wait its turn instead of immediately raising SQLITE_BUSY.

If you change this, run bundle exec rake db:check_concurrency to verify SQLITE_BUSY is still avoided under concurrent test-run writes and status polling (see lib/inferno/utils/db_concurrency_check.rb for why that's a rake task and not a spec).



24
25
26
27
28
29
30
31
# File 'lib/inferno/config/boot/db.rb', line 24

def configure_sqlite_pragmas!(config)
  return config unless config['adapter'] == 'sqlite'

  connect_sqls = ["PRAGMA busy_timeout = #{ENV.fetch('DB_BUSY_TIMEOUT_MS', '15000')}"]
  connect_sqls << 'PRAGMA journal_mode = WAL' unless config['database'] == ':memory:'
  config['connect_sqls'] = connect_sqls
  config
end

.log_sqlite_journal_mode(config, connection, logger) ⇒ Object



33
34
35
36
37
38
# File 'lib/inferno/config/boot/db.rb', line 33

def log_sqlite_journal_mode(config, connection, logger)
  return unless config['adapter'] == 'sqlite'

  actual_journal_mode = connection.fetch('PRAGMA journal_mode').first[:journal_mode]
  logger.info("sqlite journal_mode: #{actual_journal_mode}")
end