import type { SqliteDatabase } from '../sqlite/sqlite-driver.js'; import type { LoopBeeRelation, LoopBeeRelationRole } from './loop-bee-relation-types.js'; /** * Low-level SQLite access for the `loop_bee_relation` table. The * migration is registered with the existing `openStateDb()` pipeline * via `src/services/skillhub/migrations/003-loop-bee-relation.sql` * (it applies every `*.sql` file in lexicographic order). The function * `ensureLoopBeeRelationTable` below is a belt-and-suspenders re-applier * for callers that pass a database they built themselves (e.g. tests). * * Defense in depth: * - FK constraints enforce loop_release and bee_release referential * integrity (foreign_keys = ON, applied by `openStateDb`). * - Partial unique index `WHERE role = 'main'` enforces "at most one * main bee per loop" at the storage layer (the service layer adds * a friendlier error path on top). * - UNIQUE (loop_release_id, bee_release_id) prevents accidental * duplicate relations between the same loop and same bee release. * - Lifecycle_status check on loop_release is NOT a DB-level constraint * (the retirement rule is enforced in the service layer — see * `LoopBeeRelationService.create`) so the DB stays decoupled from * cross-table policies that need richer error reporting. */ /** * Re-apply the loop_bee_relation table migration against an already-open * database. Used by tests that build their own DB without the * openStateDb pipeline. Idempotent. */ export declare function ensureLoopBeeRelationTable(db: SqliteDatabase): void; /** * Insert a LoopBeeRelation row. The row's `schema_version` is taken from * the input (must equal `peaks.loop-bee-relation/1`); `id` and * `created_at` are stamped here, so callers cannot backdate a row. * * Idempotent in the UNIQUE sense — re-inserting the same * (loop_release_id, bee_release_id) pair throws a UNIQUE-constraint * error; inserting two `main` rows for the same loop throws a partial * unique index error. * * Returns the persisted row (with `id` filled in). */ export declare function insertLoopBeeRelation(db: SqliteDatabase, row: Omit): LoopBeeRelation; /** Read a single LoopBeeRelation row by id; returns undefined if absent. */ export declare function getLoopBeeRelation(db: SqliteDatabase, id: number): LoopBeeRelation | undefined; /** List LoopBeeRelation rows for a given loop_release_id (optionally filtered by role). */ export declare function listLoopBeeRelationsByLoop(db: SqliteDatabase, loop_release_id: string, role?: LoopBeeRelationRole): LoopBeeRelation[]; /** List LoopBeeRelation rows for a given bee_release_id (optionally filtered by role). */ export declare function listLoopBeeRelationsByBee(db: SqliteDatabase, bee_release_id: number, role?: LoopBeeRelationRole): LoopBeeRelation[]; /** Update the role of an existing relation. Returns the new row, or undefined if absent. */ export declare function updateLoopBeeRelationRole(db: SqliteDatabase, id: number, newRole: LoopBeeRelationRole): LoopBeeRelation | undefined; /** Remove a LoopBeeRelation row by id. Returns true if a row was deleted. */ export declare function removeLoopBeeRelation(db: SqliteDatabase, id: number): boolean;