Changeset 0.8.0 (#39)
This commit is contained in:
28
server/database/migrations/013_message_forking.sql
Normal file
28
server/database/migrations/013_message_forking.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
-- ==========================================
|
||||
-- Migration 013: Message Forking Support
|
||||
-- ==========================================
|
||||
-- Adds soft delete and sibling ordering to support
|
||||
-- conversation forking (edit, regenerate, branch).
|
||||
-- See ARCHITECTURE.md §8 for the full tree model.
|
||||
-- ==========================================
|
||||
|
||||
-- Soft delete: pruned branches keep their structure for undo
|
||||
ALTER TABLE messages ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;
|
||||
|
||||
-- Sibling ordering: explicit position among children of same parent
|
||||
-- First child = 0, second = 1, etc. Set at insert time.
|
||||
ALTER TABLE messages ADD COLUMN IF NOT EXISTS sibling_index INTEGER DEFAULT 0;
|
||||
|
||||
-- Partial index: fast lookup of live messages only
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_alive
|
||||
ON messages(channel_id, created_at)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
-- Children of a parent (for sibling queries)
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_parent_alive
|
||||
ON messages(parent_id, sibling_index)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
-- Backfill sibling_index for existing messages.
|
||||
-- In linear conversations every message is the sole child of its parent,
|
||||
-- so all get sibling_index = 0 (already the default). No update needed.
|
||||
Reference in New Issue
Block a user