Allow overriding SQLite defaults from database.yml#50460
Conversation
|
@rafaelfranca @eileencodes @matthewd: Following the conversation in #49691, I put together this alternative which follows Matthew's preferences expressed in the discussion there. Honestly, hearing @suwyn's situation, it was an oversight on my part to not include the ability to override the new defaults in the first place. |
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
Outdated
Show resolved
Hide resolved
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
Outdated
Show resolved
Hide resolved
de62858 to
3055e70
Compare
|
Maybe we could add test cases for setting each of the pragmas, in either string or symbol? I know it's kind of testing |
|
Yeah, low cost to add the tests, and then CI will definitely catch any regressions, if introduced, on either Rails' side of with the SQLite3 gem. I'll add more tests today |
3055e70 to
627adee
Compare
|
@zzak: Tests added for each pragma (in addition to the one test for setting a non-default pragma and for setting an unknown pragma). Covered positive and error conditions for each pragma |
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
Outdated
Show resolved
Hide resolved
e0daaee to
6589b90
Compare
|
@zzak I pushed a fix for the test failures, but CI didn't rerun. Not sure what I did differently/wrong, as I'm pretty sure I followed the same process that I always do. Anyway, if there is any way to rerun CI, I'm confident tests will go green. |
Hopefully this can be retired once this can be configured: rails/rails#50460
Any PRAGMA configuration set under the `pragmas` key in the configuration file take precedence over Rails' defaults, and additional PRAGMAs can be set as well. ```yaml database: storage/development.sqlite3 timeout: 5000 pragmas: synchronous: full temp_store: memory ```
42c4d98 to
df75954
Compare
Any PRAGMA configuration set under the `pragmas` key in the configuration file take precedence over Rails' defaults, and additional PRAGMAs can be set as well. ```yaml database: storage/development.sqlite3 timeout: 5000 pragmas: synchronous: full temp_store: memory ```
df75954 to
caaf868
Compare
|
@dhh: No idea what is up with the ujs test failures 🤷 but the rest is good to go. I simplified the error message expectation to be more resilient by only checking the core part of the error message. Aside from whatever is up with these ujs tests, everything related to this PR is green. And thanks for the style fix. |
…hancedsqlite3-adapter Most of the enhancements provided by activerecord-enhancedsqlite3-adapter have been upstreamed into Rails, including: * Add support for generated columns in SQLite3 adapter rails/rails#49346 * Add SQLite3 support for supports_insert_returning? rails/rails#49290 * Allow overriding SQLite defaults from database.yml rails/rails#50460 * Performance tune the SQLite3 adapter connection configuration rails/rails#49349 * Allow SQLite3 busy_handler to be configured with simple max number of retries rails/rails#49352 One enhancement Joy still needs is a way to load SQLite3 extensions. There is a sqlpkg gem that would provide this, which includes generating an initializer that overrides the Rails SQLite3 adapter. Instead, I‘ve just adapted the enhancedsqlite3-adapter code and droppped into the lib/ directory. The code here also knows how to load an extension by gem name which is makes it useful for the sqlite_ulid gem currently in use.
…hancedsqlite3-adapter Most of the enhancements provided by activerecord-enhancedsqlite3-adapter have been upstreamed into Rails, including: * Add support for generated columns in SQLite3 adapter rails/rails#49346 * Add SQLite3 support for supports_insert_returning? rails/rails#49290 * Allow overriding SQLite defaults from database.yml rails/rails#50460 * Performance tune the SQLite3 adapter connection configuration rails/rails#49349 * Allow SQLite3 busy_handler to be configured with simple max number of retries rails/rails#49352 One enhancement Joy still needs is a way to load SQLite3 extensions. There is a sqlpkg gem that would provide this, which includes generating an initializer that overrides the Rails SQLite3 adapter. Instead, I‘ve just adapted the enhancedsqlite3-adapter code and droppped into the lib/ directory. The code here also knows how to load an extension by gem name which is makes it useful for the sqlite_ulid gem currently in use.
…hancedsqlite3-adapter Most of the enhancements provided by activerecord-enhancedsqlite3-adapter have been upstreamed into Rails, including: * Add support for generated columns in SQLite3 adapter rails/rails#49346 * Add SQLite3 support for supports_insert_returning? rails/rails#49290 * Allow overriding SQLite defaults from database.yml rails/rails#50460 * Performance tune the SQLite3 adapter connection configuration rails/rails#49349 * Allow SQLite3 busy_handler to be configured with simple max number of retries rails/rails#49352 One enhancement Joy still needs is a way to load SQLite3 extensions. There is a sqlpkg gem that would provide this, which includes generating an initializer that overrides the Rails SQLite3 adapter. Instead, I‘ve just adapted the enhancedsqlite3-adapter code and droppped into the lib/ directory. The code here also knows how to load an extension by gem name which is makes it useful for the sqlite_ulid gem currently in use.
* Allow overriding SQLite defaults from `database.yml` Any PRAGMA configuration set under the `pragmas` key in the configuration file take precedence over Rails' defaults, and additional PRAGMAs can be set as well. ```yaml database: storage/development.sqlite3 timeout: 5000 pragmas: synchronous: full temp_store: memory ``` * Style * Allow overriding SQLite defaults from `database.yml` Any PRAGMA configuration set under the `pragmas` key in the configuration file take precedence over Rails' defaults, and additional PRAGMAs can be set as well. ```yaml database: storage/development.sqlite3 timeout: 5000 pragmas: synchronous: full temp_store: memory ``` --------- Co-authored-by: David Heinemeier Hansson <david@hey.com>

Any PRAGMA configuration set under the
pragmaskey in the configuration file take precedence over Rails' defaults, and additional PRAGMAs can be set as well.Motivation / Background
This is an alternative to #49691, following @matthewd's suggestions.
Detail
This Pull Request allows the 7.1 default SQLite configuration to be overridden via values set under the
pragmaskey in thedatabase.ymlfile. Moreover, it allows other SQLite PRAGMAs to be set via thepragmaskey, and will ignore and warn for any unknown pragmas.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]