Close TD-20 sqlite pool alignment
This commit is contained in:
11
TECHDEBTS.md
11
TECHDEBTS.md
@@ -766,7 +766,16 @@ instructions (AGENTS.md) updated to mention them.
|
||||
|
||||
## Phase 5 — Consistency, config & hygiene
|
||||
|
||||
### TD-20: Align SQLite pool configuration between dev and prod
|
||||
### TD-20: Align SQLite pool configuration between dev and prod ✅ DONE (2026-06-12)
|
||||
|
||||
**Status: implemented.** The effective mismatch was narrowed to one place:
|
||||
`config.exs`, `dev.exs`, `prod.exs`, and `test.exs` were already aligned on a
|
||||
modest pool of `5`, but `config/runtime.exs` still defaulted production to
|
||||
`POOL_SIZE=1`. The prod runtime default now also uses `5`, with an inline
|
||||
comment documenting the rationale: keep SQLite concurrency behavior consistent
|
||||
across dev and prod under the existing WAL + `busy_timeout` setup unless an
|
||||
operator explicitly overrides `POOL_SIZE`. A regression test reads
|
||||
`config/runtime.exs` in `:prod` and locks that default to `5`.
|
||||
|
||||
**Context.** Dev runs `pool_size: 5` (config.exs), prod runs `pool_size: 1`
|
||||
(runtime.exs) — so dev and prod have **different concurrency semantics**: dev
|
||||
|
||||
@@ -7,9 +7,11 @@ if config_env() == :prod do
|
||||
|
||||
File.mkdir_p!(Path.dirname(database_path))
|
||||
|
||||
# Keep prod on the same modest SQLite pool as dev so WAL + busy_timeout see
|
||||
# the same concurrency behavior in both environments unless explicitly tuned.
|
||||
config :bds, BDS.Repo,
|
||||
database: database_path,
|
||||
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "1")
|
||||
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5")
|
||||
|
||||
# Persist downloaded embedding model files alongside the database data dir.
|
||||
config :bumblebee,
|
||||
|
||||
@@ -85,6 +85,32 @@ defmodule BDS.Repo.BootstrapTest do
|
||||
assert repo_config[:busy_timeout] == 15_000
|
||||
end
|
||||
|
||||
test "prod runtime repo config defaults to the same pool size as dev" do
|
||||
config_path = Path.expand("../../../config/runtime.exs", __DIR__)
|
||||
database_path = Path.join(System.tmp_dir!(), "bds-runtime-#{System.unique_integer([:positive])}.db")
|
||||
|
||||
previous_pool_size = System.get_env("POOL_SIZE")
|
||||
previous_database_path = System.get_env("BDS_DATABASE_PATH")
|
||||
|
||||
System.delete_env("POOL_SIZE")
|
||||
System.put_env("BDS_DATABASE_PATH", database_path)
|
||||
|
||||
on_exit(fn ->
|
||||
restore_env("POOL_SIZE", previous_pool_size)
|
||||
restore_env("BDS_DATABASE_PATH", previous_database_path)
|
||||
File.rm_rf(Path.dirname(database_path))
|
||||
end)
|
||||
|
||||
config = Config.Reader.read!(config_path, env: :prod)
|
||||
|
||||
repo_config =
|
||||
config
|
||||
|> Keyword.fetch!(:bds)
|
||||
|> Keyword.fetch!(BDS.Repo)
|
||||
|
||||
assert repo_config[:pool_size] == 5
|
||||
end
|
||||
|
||||
defmodule RepoConfigBackup do
|
||||
def put_env do
|
||||
Process.put({__MODULE__, :temp_repo_config}, Application.get_env(:bds, TempRepo))
|
||||
@@ -97,4 +123,7 @@ defmodule BDS.Repo.BootstrapTest do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp restore_env(key, nil), do: System.delete_env(key)
|
||||
defp restore_env(key, value), do: System.put_env(key, value)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user