Skip to main content

migrate_sqlite_memory_to_v3

Function migrate_sqlite_memory_to_v3 

Source
pub fn migrate_sqlite_memory_to_v3(
    db_path: &Path,
    conn: &Connection,
) -> Result<()>
Expand description

Migrate a SQLite memory database to the V3 multi-agent shape.

Adds the agents table, the agent_id column on memories, backfills existing rows to a synthesized default agent, and promotes the column to NOT NULL REFERENCES agents(id) via a table rebuild. Idempotent: re-running on an already-migrated DB is a no-op. Before any destructive step the file is backed up at <db_path>.backup-<ts> when there are rows that would be touched.

The caller is responsible for opening the connection with PRAGMA foreign_keys = ON (and any other backend-specific PRAGMA tuning); this function operates on the open connection.