pub async fn open(
path: &Path,
user_templates: Option<Vec<DcsTemplate>>,
retention_days: Option<u32>,
) -> Result<SqlitePool>Expand description
Opens (creating if necessary) the database at path, running migrations, then upserts the
built-in templates via bhtune_db::seed_builtin_templates so a fresh database is
immediately usable without a separate setup step. If user_templates is Some (the
caller found and parsed a user catalog file – see crate::config::load_user_templates,
template-user-catalog), those templates are additionally upserted with
TemplateOrigin::Catalog via bhtune_db::seed_templates. None means no user
catalog file was found at all, which is not an error and simply skips this second seed
pass – the common case, since most installs never create templates.toml.
If retention_days is Some (see crate::config::resolve_retention_days), also runs
crate::retention::sweep_retention once before returning – the “on startup” half of
history-retention’s policy, shared by both binaries since both call this function.
None (the default) skips the sweep entirely: no query, no log line, nothing – matching
“ships disabled by default (retain forever)”. A sweep failure is propagated (?) rather
than logged-and-ignored: unlike bhtune-server’s periodic re-sweep (which must not crash
a process that may be mid-tune just because a housekeeping query failed), this runs before
any command has done anything yet, so failing fast with a clear error is strictly better
than silently proceeding on what might be a genuinely broken database.
Creates path’s parent directory tree first: bhtune_db::connect’s
SqliteConnectOptions::create_if_missing(true) only creates the database file, not any
missing parent directories – necessary now that the default database path (see
crate::config::default_db_path_from) is a nested, not-yet-existing platform directory
(e.g. ~/.local/share/bhtune/) on a genuinely fresh install.