Files
upstream-tldraw/apps/dotcom/zero-cache/migrations/043_add_comment_reactions.sql
upstream-mirror a774ac673a
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
snapshot of https://github.com/tldraw/tldraw.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 16:12:52 +05:00

44 lines
2.6 KiB
SQL

-- Emoji reactions on comments, written by the file's Durable Object from the room's
-- comment-reaction records (see TLCommentReaction in tlschema). Same contract as comment and
-- comment_thread: Postgres is the sole durable store, the columns carry every record field so the
-- Durable Object can rebuild the records from rows alone on cold start, and `lastChangedClock`
-- preserves each record's sync clock and guards upserts against no-op replays.
--
-- A reaction is its own row rather than a column on comment because it is one user's data about
-- someone else's comment — the same reason comment_read is its own table. It keeps every write
-- scoped to one user's own record, so concurrent reactions from different people can't overwrite
-- each other, and a user can never write a reaction attributed to anyone else.
--
-- `meta` and `lastChangedClock` are persistence/rehydration columns not declared in the Zero
-- schema, so they never reach clients.
CREATE TABLE comment_reaction (
"id" VARCHAR PRIMARY KEY,
"fileId" VARCHAR NOT NULL,
"commentId" VARCHAR NOT NULL,
"threadId" VARCHAR NOT NULL,
"pageId" VARCHAR NOT NULL,
"userId" VARCHAR NOT NULL,
"emoji" VARCHAR NOT NULL,
"createdAt" BIGINT NOT NULL,
"meta" JSONB NOT NULL,
"lastChangedClock" BIGINT NOT NULL,
CONSTRAINT comment_reaction_file_id_fkey FOREIGN KEY ("fileId") REFERENCES public."file"("id") ON DELETE CASCADE,
CONSTRAINT comment_reaction_comment_id_fkey FOREIGN KEY ("commentId") REFERENCES public."comment"("id") ON DELETE CASCADE,
CONSTRAINT comment_reaction_thread_id_fkey FOREIGN KEY ("threadId") REFERENCES public."comment_thread"("id") ON DELETE CASCADE,
-- deleting a user removes their reactions, never the comment they reacted to
CONSTRAINT comment_reaction_user_id_fkey FOREIGN KEY ("userId") REFERENCES public."user"("id") ON DELETE CASCADE,
-- one record per (comment, user, emoji): a user may hold multiple reactions on a comment (one
-- per emoji), but not the same emoji twice. The record id is derived from the same triple
-- (createCommentReactionId), so this backstops the invariant at the database.
CONSTRAINT comment_reaction_comment_user_emoji_unique UNIQUE ("commentId", "userId", "emoji")
);
CREATE INDEX comment_reaction_file_id_idx ON comment_reaction("fileId");
CREATE INDEX comment_reaction_comment_id_idx ON comment_reaction("commentId");
CREATE INDEX comment_reaction_thread_id_idx ON comment_reaction("threadId");
-- covers the user-delete cascade path
CREATE INDEX comment_reaction_user_id_idx ON comment_reaction("userId");
ALTER PUBLICATION zero_data ADD TABLE public."comment_reaction";