Moves the chat's unread state to the server, so that it survives a reload and agrees across tabs and devices. users.chat_read_at holds the time of the newest message the user has seen.

It also replaces the index on created_at with one on (created_at, id), which the history now pages on, so that two messages from the same millisecond can't fall between two pages.

Functions

f
up(db: DatabaseSync): void

Run once by runMigrations. Existing users start with every message read, instead of the whole history unread. A user created later starts with a NULL chat_read_at, which chat-service reads as the user's creation time.

Usage

import * as mod from "api/db/migrations/0014_chat_read_state.ts";