Normalize companion_hash format in SQLite migrations to include 0x prefix

- Updated the SQLiteHandler to apply a migration that prefixes companion_hash values with '0x' for consistency with room_hash patterns.
- Adjusted the main.py file to reflect the new formatting for companion_hash when generating its string representation.
This commit is contained in:
agessaman
2026-02-28 09:06:24 -08:00
parent d5fe1e637c
commit d82ebc59b0
2 changed files with 20 additions and 1 deletions

View File

@@ -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:

View File

@@ -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)