migrate_kg_uuids

One-time migration: assign UUID7 to all KG entities and stamp src_uuid / tgt_uuid on all relationships.

Idempotent – only touches nodes/edges where the uuid fields are NULL.

Usage:

python migrate_kg_uuids.py [--redis-url redis://localhost:6379/0]
async migrate_kg_uuids.migrate(redis_url, ssl_kwargs=None)[source]

Backfill UUID7 identifiers across the knowledge graph.

Walks the knowledge FalkorDB graph and, in three steps, assigns a fresh uuid7 to every entity whose uuid property is NULL, then stamps src_uuid / tgt_uuid onto every relationship from its endpoints’ UUIDs, then verifies that no nodes or edges remain unstamped. The migration is idempotent: only NULL fields are touched, so re-running it leaves already-stamped records alone.

Opens an async Redis connection at redis_url (its pool also backing the FalkorDB client named by GRAPH_NAME) and issues per-node and bulk Cypher query calls; entity UUIDs are written one node at a time while relationship stamping is a single set-based query. Progress, counts, and any still-missing UUIDs are reported through the module logger (warnings on leftovers), and the Redis client is always closed in a finally block. Called by this module’s main via asyncio.run; not imported elsewhere.

Parameters:
  • redis_url (str) – Redis connection URL whose pool also backs FalkorDB.

  • ssl_kwargs (dict | None) – Optional SSL/mTLS keyword arguments forwarded to aioredis.from_url (typically from Config.redis_ssl_kwargs).

Return type:

None

Returns:

None.

migrate_kg_uuids.main()[source]

Parse CLI arguments and run the UUID backfill migration.

Command-line entry point for python migrate_kg_uuids.py. Parses --redis-url (defaulting to $REDIS_URL or redis://localhost:6379/0), best-effort loads SSL/mTLS settings from Config.redis_ssl_kwargs so a TLS-protected Redis can be reached, and hands both to migrate through asyncio.run.

Invoked only from this module’s if __name__ == "__main__" guard; it has no in-repo callers. Logging is configured at import time at module scope.

Return type:

None

Returns:

None.

Raises:

SystemExit – Raised by argparse when given invalid arguments.