Skip to main content

ensure_db_ready

Function ensure_db_ready 

Source
pub fn ensure_db_ready(paths: &AppPaths) -> Result<(), AppError>
Expand description

Ensures the database file exists and the schema is at the current version.

Behavior:

  • DB does not exist: creates the file, applies init PRAGMAs, runs all migrations, sets PRAGMA user_version, and populates schema_meta with default values. Emits tracing::info! on creation.
  • DB exists with user_version below SCHEMA_USER_VERSION: runs the remaining migrations and updates user_version. Emits tracing::warn! on auto-migration.
  • DB exists with user_version equal to SCHEMA_USER_VERSION: no-op.

This helper unifies the auto-init contract across CRUD handlers so users can run any subcommand on a fresh directory without invoking init first. Idempotent and safe to call before every handler that needs a ready database.