feat: 0014 schema — embeddings FK CASCADE (deferred or applied) + memories.event_id column (T109)
This commit is contained in:
@@ -586,3 +586,59 @@ def test_record_turn_memory_enqueues_embedding_job(tmp_path):
|
||||
assert {job.memory_id for job in captured} == expected_ids
|
||||
for job in captured:
|
||||
assert job.text == "Both bots witness this beat."
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# T109: memories.event_id deep-link column populated by the projector.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_memory_written_populates_event_id(tmp_path):
|
||||
"""Schema 0014 added ``memories.event_id`` referencing ``event_log.id``.
|
||||
|
||||
The ``memory_written`` projector handler must populate the column with
|
||||
the projecting event's id so T111 can deep-link cross-chat search hits
|
||||
back to the originating turn.
|
||||
"""
|
||||
db = tmp_path / "t.db"
|
||||
apply_migrations(db)
|
||||
_seed_minimal(db)
|
||||
with open_db(db) as conn:
|
||||
result = record_turn_memory_for_present(
|
||||
conn,
|
||||
chat_id="chat_bot_a",
|
||||
host_bot_id="bot_a",
|
||||
guest_bot_id=None,
|
||||
narrative_text="BotA shrugs.",
|
||||
)
|
||||
eid, mid = result["bot_a"]
|
||||
assert eid > 0 and mid is not None
|
||||
|
||||
row = conn.execute(
|
||||
"SELECT event_id FROM memories WHERE id = ?", (mid,)
|
||||
).fetchone()
|
||||
assert row is not None
|
||||
assert row[0] == eid
|
||||
|
||||
|
||||
def test_memory_event_id_column_is_nullable_for_backfill(tmp_path):
|
||||
"""Backward compat: the ``event_id`` column is nullable so historical
|
||||
memory rows projected before 0014 ran (or rows synthesised by tests
|
||||
that bypass the projector) don't break the schema. A direct INSERT
|
||||
omitting the column must succeed and read back NULL."""
|
||||
db = tmp_path / "t.db"
|
||||
apply_migrations(db)
|
||||
_seed_minimal(db)
|
||||
with open_db(db) as conn:
|
||||
conn.execute(
|
||||
"INSERT INTO memories ("
|
||||
"owner_id, chat_id, pov_summary, "
|
||||
"witness_you, witness_host, witness_guest"
|
||||
") VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("bot_a", "chat_bot_a", "legacy row", 1, 1, 0),
|
||||
)
|
||||
row = conn.execute(
|
||||
"SELECT event_id FROM memories WHERE pov_summary = 'legacy row'"
|
||||
).fetchone()
|
||||
assert row is not None
|
||||
assert row[0] is None
|
||||
|
||||
+2
-2
@@ -324,11 +324,11 @@ def test_get_scene_returns_none_for_missing(tmp_path):
|
||||
assert active_scene(conn, "chat_missing") is None
|
||||
|
||||
|
||||
def test_schema_version_after_migration_is_13(tmp_path):
|
||||
def test_schema_version_after_migration_is_14(tmp_path):
|
||||
db = tmp_path / "t.db"
|
||||
apply_migrations(db)
|
||||
with open_db(db) as conn:
|
||||
row = conn.execute(
|
||||
"SELECT value FROM meta WHERE key = 'schema_version'"
|
||||
).fetchone()
|
||||
assert int(row[0]) == 13
|
||||
assert int(row[0]) == 14
|
||||
|
||||
Reference in New Issue
Block a user