From a73af6b44df23c8c4c04434fe20de99f3e903c31 Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Fri, 12 Jun 2026 14:07:28 +0200 Subject: [PATCH] Close TD-20 sqlite pool alignment --- TECHDEBTS.md | 11 ++++++++++- config/runtime.exs | 4 +++- test/bds/repo/bootstrap_test.exs | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/TECHDEBTS.md b/TECHDEBTS.md index 25cf15f..9a8c6e7 100644 --- a/TECHDEBTS.md +++ b/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 diff --git a/config/runtime.exs b/config/runtime.exs index 289a676..22cdfcb 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -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, diff --git a/test/bds/repo/bootstrap_test.exs b/test/bds/repo/bootstrap_test.exs index 6b249d8..c0e69db 100644 --- a/test/bds/repo/bootstrap_test.exs +++ b/test/bds/repo/bootstrap_test.exs @@ -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