/** * Migration registry access (SPEC_F §F.5). * Run metadata, dirty key tracking, and error logging. */ import type Database from '../storage/sqlite/driver.ts'; declare const RUN_STATUS: { readonly RUNNING: 'running'; readonly PAUSED: 'paused'; readonly COMPLETED: 'completed'; readonly FAILED: 'failed'; readonly ABORTED: 'aborted'; }; export type RunStatus = (typeof RUN_STATUS)[keyof typeof RUN_STATUS]; /** State of a key in `migration_dirty_keys`. */ export type DirtyKeyState = 'dirty' | 'deleted' | 'applied' | 'skipped' | 'error'; /** Migration step that logged an error. */ export type MigrationErrorStage = 'bulk' | 'dirty_apply' | 'verify'; /** A `migration_runs` row. */ export interface MigrationRun { run_id: string; source_uri: string; started_at: number; updated_at: number; status: RunStatus; scan_cursor: string; scan_count_hint: number; scanned_keys: number; migrated_keys: number; skipped_keys: number; error_keys: number; migrated_bytes: number; dirty_keys_seen: number; dirty_keys_applied: number; dirty_keys_deleted: number; last_error: string | null; } export interface CreateRunOptions { scan_count_hint?: number; } export interface CreateRunResult { run_id: string; created: boolean; } /** Bulk import progress fields to persist; omitted fields keep their stored value. */ export interface BulkProgressUpdate { scan_cursor?: string; scanned_keys?: number; migrated_keys?: number; skipped_keys?: number; error_keys?: number; migrated_bytes?: number; last_error?: string | null; } /** Count of dirty keys per state for a run. */ export type DirtyCounts = Record; /** * Create a new migration run. Idempotent: if run_id exists, return it. */ export declare function createRun(db: Database, runId: string, sourceUri: string, options?: CreateRunOptions): CreateRunResult; export declare function getRun(db: Database, runId: string): MigrationRun | undefined; export declare function setRunStatus(db: Database, runId: string, status: RunStatus): void; /** * Update bulk import progress (cursor and counters). */ export declare function updateBulkProgress(db: Database, runId: string, updates: BulkProgressUpdate): void; /** * Upsert a dirty key (tracker saw an event). State: dirty or deleted per event type (SPEC_F F.6.2, F.6.3). * @param event - e.g. "set", "hset", "del", "expired" */ export declare function upsertDirtyKey(db: Database, runId: string, key: Buffer | string, event: string): void; /** * Get a batch of dirty keys for delta apply. ORDER BY last_seen_at ASC, LIMIT. * @param state - 'dirty' */ export declare function getDirtyBatch(db: Database, runId: string, state: DirtyKeyState, limit: number): { key: Buffer; }[]; /** * Mark a dirty key as applied or deleted and update run counters. */ export declare function markDirtyState(db: Database, runId: string, key: Buffer | string, state: 'applied' | 'deleted' | 'skipped' | 'error'): void; /** * Log an error for the run (bounded table; consider retention in production). */ export declare function logError(db: Database, runId: string, stage: MigrationErrorStage, message: string, key?: Buffer | string | null): void; /** * Get count of dirty keys by state for a run. */ export declare function getDirtyCounts(db: Database, runId: string): DirtyCounts; export { RUN_STATUS };