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
-
.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.
- .log_sqlite_journal_mode(config, connection, logger) ⇒ Object
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.
19 20 21 22 23 24 25 26 |
# File 'lib/inferno/config/boot/db.rb', line 19 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
28 29 30 31 32 33 |
# File 'lib/inferno/config/boot/db.rb', line 28 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 |