Files
resource-scraper/types/model/srrdb.go
T
Yevhen Odynets a2bfa8ea71 srrdb: persist per-day harvest ledger alongside releases
Add srrdb_log table with composite primary key (day, category) and counters
found, stored, ignored plus run_at.

Replace the release-only persistence path with UpsertAllSrrdbWithDay so releases
and their corresponding srrdb_log row are written in one SQLite transaction.
Preserve existing error handling: rollback reports the release/day that failed,
and commit errors return without writing a dump.

Handle fully ignored days as closed. When every fetched release is skipped by
ignore rules, still write the ledger row with zero stored releases. This prevents
the automatic day walk from endlessly retrying a day whose releases are filtered
out.

Derive and validate the ledger day from the resolved request URI. Missing or
invalid date: segments now fail before database writes. Keep run_at independent
from created_at semantics and continue populating created_at from the run time.

Preserve column and upsert semantics. category continues to use NOT NULL DEFAULT
empty string; status keeps COALESCE behavior on conflict; nfo, content, and
synced_at remain unchanged.
2026-09-30 12:44:40 +03:00

35 lines
1.2 KiB
Go

package model
// SrrdbRelease is one row of the srrdb_releases table described by
// internal/db/srrdb.sql. Release is the primary key, therefore a repeated
// search rewrites the previous row of the same release instead of inserting
// a copy. Columns left nil are stored as NULL.
type SrrdbRelease struct {
Release string `db:"release"`
Date string `db:"date"`
HasNfo string `db:"has_nfo"`
HasSrs string `db:"has_srs"`
IsForeign string `db:"is_foreign"`
ImdbID *string `db:"imdb_id"`
Size int64 `db:"size"`
GroupName string `db:"group_name"`
Category string `db:"category"`
Status *string `db:"status"`
Nfo []byte `db:"nfo"`
Content *string `db:"content"`
CreatedAt string `db:"created_at"`
SyncedAt *string `db:"synced_at"`
}
// SrrdbLog is one row of the srrdb_log table: per-day, per-category
// accounting of a harvest run. Written in the same transaction as the
// releases, so a day marked there always matches what landed in srrdb_releases.
type SrrdbLog struct {
Day string `db:"day"`
Category string `db:"category"`
Found int `db:"found"`
Stored int `db:"stored"`
Ignored int `db:"ignored"`
RunAt string `db:"run_at"`
}