db: add `expires_at column and expiration management methods

Schema v4: add expires_at REAL column with partial index for NULL values

Other relevant methods that were added:

- `now()` for Unix timestamp with sub-second precision
- `cleanup_expired()` to remove all expired entries
- `get_expired_entries()` for for diagnostic output (`stash list --expired`)
- `get_next_expiration()` for heap initialization
- `set_expiration()` to update expiration timestamp

This feature has proven larger than I had anticipated (and hoped) but
that's the reality of dealing with databases. Some of the methods are
slightly redundant but it helps keep tracing the code manageable and
semantically correct. We'll probably not regret those later. Probably.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ie9e5b0767673e74389b8e59c466afd946a6a6964
This commit is contained in:
raf 2026-01-22 14:32:00 +03:00
commit 71fc1ff40f
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 150 additions and 15 deletions

View file

@ -10,7 +10,7 @@ repository = "https://github.com/notashelf/stash"
rust-version = "1.90"
[[bin]]
name = "stash" # actual binary name for Nix, Cargo, etc.
name = "stash" # actual binary name for Nix, Cargo, etc.
path = "src/main.rs"
[dependencies]
@ -22,6 +22,7 @@ crossterm = "0.29.0"
ctrlc = "3.5.1"
dirs = "6.0.0"
env_logger = "0.11.8"
humantime = "2.3.0"
imagesize = "0.14.0"
inquire = { version = "0.9.2", default-features = false, features = [
"crossterm",