KeiSeiKit-1.0/_primitives/_rust/kei-prune/src/schema.rs
Parfii-bot 0be354a920 KeiSeiKit-public — clean state
Single-commit clean baseline after security scrub of niche-tells,
project codenames, internal jargon, and contributor-email leaks.

Contents:
- 100 Rust crates (_primitives/_rust/)
- 37 agent manifests (_manifests/) + generated specs (_generated/)
- 67 user-invocable skills (skills/)
- 33 hooks (hooks/)
- Composition blocks (_blocks/)
- Documentation (docs/, README.md)
- TS adapter packages (_ts_packages/)
- Assembler (_assembler/)
- Roles (_roles/)
- Templates (_templates/)
- Forgejo CI (.forgejo/)

Author: Denis Parfionovich <info@greendragon.info>

License: see LICENSE.
2026-05-01 12:09:03 +08:00

36 lines
1.4 KiB
Rust

//! Schema for the pruning sidecar.
//!
//! Constructor Pattern: one cube = sidecar DDL + idempotent installer.
//! We deliberately do NOT touch the `agents` table CHECK constraint —
//! that is owned by kei-ledger and cannot be extended from outside
//! without risking a migration desync. Instead we keep a lightweight
//! companion table keyed on the same `agent_id`.
use crate::error::PruneError;
use rusqlite::Connection;
/// DDL for the `prune_retirements` sidecar.
///
/// - `agent_id` — matches `agents.id` (no FK because SQLite foreign_keys
/// pragma is often off; we validate in `mark_retired` instead).
/// - `retired_ts` — unix-seconds timestamp when retirement was recorded.
///
/// The table is append-only in spirit: `mark_retired` is idempotent and
/// leaves the original `retired_ts` untouched on repeat calls.
pub const SIDECAR_DDL: &str = "\
CREATE TABLE IF NOT EXISTS prune_retirements (
agent_id TEXT PRIMARY KEY,
retired_ts INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_prune_retired_ts ON prune_retirements(retired_ts);
";
/// Create the sidecar table if it does not yet exist.
///
/// Idempotent: safe to call on every CLI invocation. Does not migrate
/// — if the shape ever needs to change we add a migration runner here
/// mirroring kei-ledger's pattern.
pub fn ensure_schema(conn: &Connection) -> Result<(), PruneError> {
conn.execute_batch(SIDECAR_DDL)?;
Ok(())
}