미디어 업로드와 태그 표시 수정

This commit is contained in:
2026-06-09 16:14:47 +09:00
parent e6669439f3
commit ed30926250
12 changed files with 162 additions and 32 deletions

View File

@@ -0,0 +1,21 @@
ALTER TABLE post_tags
ADD COLUMN IF NOT EXISTS sort_order INTEGER NOT NULL DEFAULT 0;
WITH ordered_post_tags AS (
SELECT
post_id,
tag_id,
(ROW_NUMBER() OVER (
PARTITION BY post_id
ORDER BY created_at ASC, tag_id ASC
) - 1) * 10 AS next_sort_order
FROM post_tags
)
UPDATE post_tags
SET sort_order = ordered_post_tags.next_sort_order
FROM ordered_post_tags
WHERE post_tags.post_id = ordered_post_tags.post_id
AND post_tags.tag_id = ordered_post_tags.tag_id;
CREATE INDEX IF NOT EXISTS post_tags_post_id_sort_order_idx
ON post_tags (post_id, sort_order ASC, created_at ASC);