diff --git a/repeater/data_acquisition/sqlite_handler.py b/repeater/data_acquisition/sqlite_handler.py index 63e0ed4..f8b1d24 100644 --- a/repeater/data_acquisition/sqlite_handler.py +++ b/repeater/data_acquisition/sqlite_handler.py @@ -404,6 +404,25 @@ class SQLiteHandler: ) logger.info(f"Migration '{migration_name}' applied successfully") + # Migration 6: Normalize companion_hash to 0x-prefixed hex (match room_hash pattern) + migration_name = "companion_hash_0x_prefix" + existing = conn.execute( + "SELECT migration_name FROM migrations WHERE migration_name = ?", + (migration_name,), + ).fetchone() + + if not existing: + for table in ("companion_contacts", "companion_channels", "companion_messages"): + conn.execute( + f"UPDATE {table} SET companion_hash = '0x' || companion_hash " + "WHERE companion_hash NOT LIKE '0x%'" + ) + conn.execute( + "INSERT INTO migrations (migration_name, applied_at) VALUES (?, ?)", + (migration_name, time.time()), + ) + logger.info(f"Migration '{migration_name}' applied successfully") + conn.commit() except Exception as e: diff --git a/repeater/main.py b/repeater/main.py index bd15856..5db5ce8 100644 --- a/repeater/main.py +++ b/repeater/main.py @@ -406,7 +406,7 @@ class RepeaterDaemon: identity = LocalIdentity(seed=identity_key_bytes) pubkey = identity.get_public_key() companion_hash = pubkey[0] - companion_hash_str = f"{companion_hash:02x}" + companion_hash_str = f"0x{companion_hash:02x}" node_name = settings.get("node_name", name) tcp_port = settings.get("tcp_port", 5000)