Summary
Follow-up hardening from PR #161.
user_embeddings currently validates provenance shape (user_message_id vs assistant_message_id, conversation_id presence, etc.), but it does not enforce at the database layer that the referenced message rows belong to the same user_id / conversation_id as the embedding row.
Why this is worth tracking
- Current write paths appear safe, so this did not block the schema-sync PR.
- A bad future write path could still create cross-user or cross-conversation provenance links.
- This is the kind of invariant that is easy to assume in code and hard to notice once violated.
Affected migration
migrations/2026-02-10-020612_user_embeddings
Follow-up direction
- Add DB-level ownership validation for
user_message_id / assistant_message_id / conversation_id.
- Composite FKs may work if the referenced tables expose the needed uniqueness; otherwise use a trigger-based validation approach.
- Preserve the existing Feb/Mar migration lineage by addressing this in a new forward migration rather than editing the historical migration files.
Summary
Follow-up hardening from PR #161.
user_embeddingscurrently validates provenance shape (user_message_idvsassistant_message_id,conversation_idpresence, etc.), but it does not enforce at the database layer that the referenced message rows belong to the sameuser_id/conversation_idas the embedding row.Why this is worth tracking
Affected migration
migrations/2026-02-10-020612_user_embeddingsFollow-up direction
user_message_id/assistant_message_id/conversation_id.