diff options
Diffstat (limited to 'src/db/migrations.rs')
| -rw-r--r-- | src/db/migrations.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/db/migrations.rs b/src/db/migrations.rs index bb8974f..9e60132 100644 --- a/src/db/migrations.rs +++ b/src/db/migrations.rs @@ -319,6 +319,35 @@ CREATE TABLE stage_b_cache ( CREATE INDEX stage_b_cache_by_pkgbase ON stage_b_cache (pkgbase_id, resolved_at); "#; +/// Retention (§15, open question 21). The rows are never compacted — the whole +/// point of the schema is that "which bytes produced this installed package" +/// stays answerable — but the bytes on disk cannot be kept forever. So eviction +/// is recorded rather than implied: the artifact row keeps its digest, size and +/// provenance and gains a `purged_at`, which says "these bytes existed, and were +/// dropped from the store at T" instead of silently pretending they are still +/// there. A `cp` of the store and a database that disagrees about what is on disk +/// is the failure mode this avoids. +const M_0008_RETENTION: &str = r#" +ALTER TABLE artifact ADD COLUMN purged_at TEXT; + +-- Set when a release's files have been evicted; NULL means the bytes are held. +ALTER TABLE release ADD COLUMN purged_at TEXT; + +-- Staging is disposable (§8.2), but "disposable" needs a definition: a dir is +-- swept when its build is terminal or unknown and the dir is older than the +-- grace period. Recording the sweep keeps a crashed-then-swept build auditable. +CREATE TABLE IF NOT EXISTS gc_run ( + id INTEGER PRIMARY KEY, + ran_at TEXT NOT NULL, + releases_kept INTEGER NOT NULL, + releases_evicted INTEGER NOT NULL, + files_removed INTEGER NOT NULL, + bytes_freed INTEGER NOT NULL, + staging_swept INTEGER NOT NULL, + detail_json TEXT NOT NULL DEFAULT '{}' +); +"#; + pub static MIGRATIONS: &[Migration] = &[ Migration { version: 1, name: "core", sql: M_0001_CORE }, Migration { version: 2, name: "build", sql: M_0002_BUILD }, @@ -327,6 +356,7 @@ pub static MIGRATIONS: &[Migration] = &[ Migration { version: 5, name: "artifact-build", sql: M_0005_ARTIFACT_BUILD }, Migration { version: 6, name: "approval-immutable", sql: M_0006_APPROVAL_IMMUTABLE }, Migration { version: 7, name: "stage-b-cache", sql: M_0007_STAGE_B_CACHE }, + Migration { version: 8, name: "retention", sql: M_0008_RETENTION }, ]; /// Default settings seeded into `settings` (DESIGN.md §11). |
