Conversation
There was a problem hiding this comment.
Code Review
This pull request enables Write-Ahead Logging (WAL) mode by default for SQLite databases to improve concurrency. It introduces a disable_sqlite_auto_wal configuration option and a helper function to automatically append the WAL pragma to the DSN if it is not already present. Feedback was provided to make the DSN check case-insensitive to prevent duplicate pragmas when user-provided strings use different casing.
| } | ||
| switch dialect { | ||
| case "sqlite3", "sqlite": | ||
| if !strings.Contains(dsn, "journal_mode") { |
There was a problem hiding this comment.
The check for journal_mode is case-sensitive. Since SQLite pragmas and connection string parameters are often treated as case-insensitive by drivers (e.g., JOURNAL_MODE=WAL), this function might incorrectly append a duplicate journal_mode pragma if the user provided one with different casing. Using a case-insensitive check is more robust.
| if !strings.Contains(dsn, "journal_mode") { | |
| if !strings.Contains(strings.ToLower(dsn), "journal_mode") { |
Greptile SummaryThis PR auto-enables WAL (Write-Ahead Logging) mode for SQLite connections by injecting
Confidence Score: 5/5Safe to merge; the WAL injection is guarded correctly and the opt-out flag is wired end-to-end. The core logic is a pure string-manipulation helper that modifies only the DSN before handing it to the existing openDB function — no schema changes, no migration changes. All existing code paths are preserved, and the new flag defaults to false so behaviour is unchanged for users who do not configure it. internal/server/db/ent.go — the journal-mode detection misses the _journal= shorthand, though this is an edge case not present in the project's own DSN patterns. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[NewEntClient called] --> B[ensureSQLiteWAL\nmaster DSN]
B --> C{DisableSQLiteAutoWAL?}
C -- true --> D[return DSN unchanged]
C -- false --> E{dialect == sqlite3\nor sqlite?}
E -- no --> D
E -- yes --> F{DSN contains\n'journal_mode'?}
F -- yes --> D
F -- no --> G{DSN contains '?'}
G -- yes --> H[append &_pragma=journal_mode WAL]
G -- no --> I[append ?_pragma=journal_mode WAL]
H --> J[openDB with WAL DSN]
I --> J
D --> J
J --> K{ReadReplica.DSN set?}
K -- yes --> L[ensureSQLiteWAL\nreplica DSN]
L --> M[openDB replica]
M --> N[newRouterDriver\nmaster + replica]
K -- no --> O[entsql.OpenDB master only]
N --> P[ent.NewClient]
O --> P
Reviews (2): Last reviewed commit: "feat: auto enable wal for sqlite" | Re-trigger Greptile |
No description provided.