penpot/backend/src/app/migrations/sql/0813-mod-file-task-add-comment.sql
Álvaro Tejero Cantero 26d3c45266
✨ Key branch reviews, threads, and tasks to the file family
A branch review, its verdicts, activity, threads, and tasks now hang
off the file family (a file and every branch cut from it), so they
outlive the branch file. Migration 0817:

- adds file_family, family_id on files and on the rows they own, real
  foreign keys for review_id and merge_id, and thread numbers per
  family, renumbered once;
- renames the review entity and its commands (file_branch_review,
  file_branch_reviewer with a nullable verdict, pinned revision
  columns), the compare marks (file_branch_change_mark, directions
  branch->source and source->branch), and the backend's main to
  source;
- derives a review's target from the branch edge.

At a merge, a thread moves to the target only when it holds an open
task, whole with its tasks, or when it was written outside any
review. Every other thread stays on the closed review, survives the
purge of the branch file, and is listed by get-branch-review-threads.
move-branch-review-thread brings one to the target later.

A branch deleted without a merge takes its reviews, threads, and
tasks with it. Branches of branches are built behind the
branch-stacking flag, off by default.

AI-assisted-by: mixed models
2026-11-23 19:23:21 +01:00

25 lines
1011 B
SQL

-- The message of a comment thread a task comes from: each message may be
-- a task, so a thread may hold several. A task has no message when it
-- comes from no thread or when its message was deleted; it then keeps its
-- thread.
ALTER TABLE file_task
ADD COLUMN comment_id uuid NULL REFERENCES comment(id) ON DELETE SET NULL DEFERRABLE;
CREATE INDEX file_task__comment_id__idx
ON file_task(comment_id) WHERE comment_id IS NOT NULL;
-- Until now a task came from a whole thread, with the title of its first
-- message.
--
-- The update has no `AND t.comment_id IS NULL` guard: it runs once, when
-- the column is new and empty. A squash that replays this step after
-- tasks hold messages must add the guard, or it rewrites their messages.
UPDATE file_task AS t
SET comment_id = (SELECT c.id
FROM comment AS c
WHERE c.thread_id = t.thread_id
ORDER BY c.created_at ASC
LIMIT 1)
WHERE t.thread_id IS NOT NULL;