# 고정 링크가 첫 번째 게시글이 아닌 토픽 URL을 가리키도록 수정

**URL:** <https://meta.discourse.org/t/fix-permalinks-to-point-to-topic-url-and-not-to-first-post-of-topic/218262>\
**Category:** Migration\
**Created:** [2월 15, 2022, 4:38오후 UTC](https://meta.discourse.org/t/fix-permalinks-to-point-to-topic-url-and-not-to-first-post-of-topic/218262 "2022-02-15T16:38:35Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![rrit](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@rrit](https://meta.discourse.org/u/rrit)\
**Post date:** [2월 15, 2022, 4:38오후 UTC](https://meta.discourse.org/t/fix-permalinks-to-point-to-topic-url-and-not-to-first-post-of-topic/218262/1 "2022-02-15T16:38:35Z")

</div>

커스터마이징된 마이그레이션 이후, 많은 영구 링크(permalink)가 주제 URL 자체 대신 해당 주제의 첫 번째 게시물을 가리키고 있었습니다.

예를 들어, 영구 링크가 다음과 같이 가리키는 경우:  
`https://forum.example.com/t/example-topic/123/1`

대신 다음과 같아야 합니다:  
`https://forum.example.com/t/example-topic/123`

* * *

### 확인 방법

아래 SQL 쿼리에 대한 레코드가 존재한다면 해당 Discourse 포럼이 영향을 받은 것입니다:

```sql
SELECT permalinks.*,
       posts.id,
       posts.topic_id,
       posts.post_number
FROM permalinks
         LEFT JOIN posts
                   ON posts.id = permalinks.post_id
WHERE permalinks.post_id IS NOT NULL
  AND posts.post_number = 1
LIMIT 20;

```

### 빠른 수정

이 쿼리는 원래 주제의 첫 번째 게시물을 가리키던 영구 링크가 주제 URL을 직접 가리키도록 변경합니다.

```sql
UPDATE permalinks
SET topic_id = posts.topic_id,
    post_id = NULL
FROM posts
WHERE permalinks.post_id = posts.id
  AND permalinks.post_id IS NOT NULL
  AND posts.post_number = 1;

```

마이그레이션 스크립트의 마지막에 실행할 좋은 정리 루틴이 될 수 있습니다.

---

_[View the full topic](https://meta.discourse.org/t/fix-permalinks-to-point-to-topic-url-and-not-to-first-post-of-topic/218262)._
