Add chat data models + migration (conversations, messages, reports)
docs/planning/social.md US-4, task 6: conversations, conversation_participants, messages (DM + world/room chat), and message_reports, following app/models/social.py's conventions (native enums, explicit index/constraint names, CASCADE FKs where appropriate). Delete behavior, chosen per-relationship: - conversations.user_a_id/user_b_id -> CASCADE: a DM is meaningless with one of its two participants gone, so it cascades away entirely (participants + messages with it). - messages.sender_id -> SET NULL: world/room chat history and reported messages must survive the sender's account being deleted, matching the existing actor-reference convention (WorldChunk.updated_by_id, WorldChunkRevision.actor_id). - messages.world_id/room_id -> CASCADE: chat scoped to a world/room has no meaning once that world/room is gone (mirrors WorldChunk). - message_reports.message_id -> SET NULL (not CASCADE): a moderation report must outlive the message it's about, mirroring WorldChunkRevision's audit-trail-survives-deletion precedent. - message_reports.reporter_id/moderator_id -> SET NULL: audit-actor references, same reasoning. Models + migration only, no endpoints, no text filtering (sibling tasks). Verified: migration upgrade/downgrade/upgrade round-trip against a real Postgres with schema inspected via \d against spec; new model tests cover DM creation, pair uniqueness + ordering check constraint, world/room messages, report defaults, and cascade behavior for both conversation-deletion and sender-deletion; full backend suite (160 tests) passes with no regressions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y2FESCaMXeJpC9gSctiEeD
This commit is contained in:
@@ -45,6 +45,11 @@ TEST_TABLES = (
|
||||
# Social graph (app/models/social.py) -- all three FK users with
|
||||
# ON DELETE CASCADE, but list explicitly for clarity/consistency.
|
||||
"friendships", "follows", "blocks",
|
||||
# Chat (app/models/chat.py). message_reports.message_id is ON DELETE SET
|
||||
# NULL (not CASCADE, deliberately -- see chat.py), so it wouldn't be
|
||||
# reached by cascading a truncate of messages/conversations; list it
|
||||
# explicitly along with the rest for clarity/consistency.
|
||||
"message_reports", "messages", "conversation_participants", "conversations",
|
||||
"sessions", "refresh_tokens", "users",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user