owpengram-server/deploy/migrations/0007_read_history_events.up.sql
2026-06-04 01:37:39 +08:00

23 lines
907 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 0007_read_history_events: persist readHistory update events for getDifference.
--
-- updateReadHistoryInbox真正发生已读推进时递增 pts并给其它 session / getDifference 留可补偿事件。
ALTER TABLE update_events
ADD COLUMN IF NOT EXISTS peer_type VARCHAR(16),
ADD COLUMN IF NOT EXISTS peer_id BIGINT,
ADD COLUMN IF NOT EXISTS max_id INT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS still_unread_count INT NOT NULL DEFAULT 0;
ALTER TABLE update_events
DROP CONSTRAINT IF EXISTS update_events_type_check;
ALTER TABLE update_events
ADD CONSTRAINT update_events_type_check
CHECK (event_type IN ('new_message', 'read_history_inbox'));
ALTER TABLE update_events
DROP CONSTRAINT IF EXISTS update_events_peer_type_check;
ALTER TABLE update_events
ADD CONSTRAINT update_events_peer_type_check
CHECK (peer_type IS NULL OR peer_type IN ('user'));