# 제 phpBB 마이그레이션 여정 (postgresql)

**URL:** https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374
**Category:** Migration
**Tags:** phpbb
**Created:** [2월 25, 2023, 8:24오후 UTC](https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374 "2023-02-25T20:24:05Z")
**Posts on this page:** 4
**Page:** 2

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [3월 26, 2023, 4:00오전 UTC](https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374/21 "2023-03-26T04:00:10Z")

</div>

소프트 삭제된 게시글이 일반 게시글로 가져와지고 있습니다(그리고 표시도 됩니다). 이는 분명히 문제입니다. 사용자가 기본적으로 소프트 삭제를 사용하는 것 같고, 삭제된 게시글에는 민감한 정보가 포함될 수 있기 때문입니다.

관련된 컬럼은 다음과 같습니다: `post_delete_user, post_delete_time, post_visibility, post_delete_reason`

`post_visibility`가 유일한 관련 컬럼인 것 같습니다. 다른 컬럼의 값은 게시글이 소프트 삭제된 후 복원되면 초기화되지 않습니다. normal = `1`, invisible = `2`

제 해결책은 소프트 삭제된 게시글을 그냥 버리는 것입니다. 누가 신경 쓰겠습니까.

마이그레이션 전에 소스 DB에서 다음을 실행하세요:

```SQL
DELETE FROM phpbb_posts WHERE post_visibility = 2;

```

---

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [3월 26, 2023, 4:22오전 UTC](https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374/22 "2023-03-26T04:22:02Z")

</div>

저는 소위 ‘연속 마이그레이션’ 파이프라인을 운영하고 있습니다. 이건 다음 같은 작업을 수행하는 셸 스크립트 모음입니다:

- 원격 서버에서 phpbb 데이터베이스, 첨부 파일 등을 가져오기
- discourse 인스턴스 생성/관리
- 템플릿 인스턴스에서 discourse 인스턴스가 생성될 때 특정 site\_settings 적용
- 백업/복원
- git 저장소의 특정 임포트 스크립트 세트로 마이그레이션 실행
- 마이그레이션 후 작업 수행

기본적으로 이 방식을 사용하면 마이그레이션 전 단계의 discourse `dctemplate` 인스턴스에서 작업하면서 설정을 제 취향대로 조정해 볼 수 있습니다.

매일 밤, 실서비스 중인 기존 phpbb에서 데이터를 가져와서 최신 템플릿으로 방금 생성한 새로운 discourse 인스턴스(`dcstaging`)에서 새로운 마이그레이션을 수행합니다.

이 작업은 물론 몇 시간이 걸리므로, 테스트용 아주 작은 데이터베이스가 있는 로컬 phpbb를 실행해 두었습니다. 이를 통해 마이그레이션 스크립트를 테스트하고 개선합니다. 다른 discourse 인스턴스(`dcdev`)에서 비교적 빠른 속도로 마이그레이션을 테스트할 수 있습니다.

따라서 낮 시간대 테스트 워크플로우는 다음과 같습니다.

템플릿에서 작업을 마쳤고 현재 상태에 만족합니다:

```bash
./dc_template_create.sh dctemplate

```

아, 템플릿에서 실수를 했습니다. 이전 상태로 복원합니다:

```bash
./dc_template_restore.sh dctemplate

```

몇 가지를 테스트하기 위해 빠른 마이그레이션을 수행합니다

```bash
# dctemplate에서 dcdev라는 새 인스턴스 생성 (그리고 dcdev에 특정 site_settings 적용)
./dc_template_restore.sh dcdev dctemplate
./dc_migrate.sh dcdev # 해당 인스턴스에 특화된 마이그레이션 스크립트 저장소를 실행

```

실제 실서비스 중인 phpbb에서 밤새 긴 마이그레이션을 수행합니다:

```bash
./dc_template_create.sh dctemplate
./dc_template_restore.sh dcstaging dctemplate

./phpbb_pull.sh
./dc_migrate.sh dcstaging
sleep 300
./dc_rake.sh dcstaging # 임포터가 처리하지 않는 추가적인 마이그레이션 후 작업 (모더레이터 생성, 상세 태그 지정, 일부 토픽 이동 등)

```

관심 있는 분이 있다면, 조금 다듬어서 공유해 드릴 수 있습니다.

---

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [3월 26, 2023, 5:03오전 UTC](https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374/23 "2023-03-26T05:03:17Z")

</div>

discourse에는 태그가 있으므로, 적절한 경우 태그를 활용하고 하위 카테고리를 제거하는 것이 현명할 수 있습니다.

하지만 제 하위 카테고리에는 각각 고정/고정된(pinned/stickied) 주제가 여러 개 있었는데, 이를 하나의 큰 카테고리로 통합하면 고정된 주제가 너무 많아져 사용자에게 혼란을 줄 수 있습니다.

제 해결 방법은 다음과 같은 카테고리 구조에서:

```plaintext
Food
- American
- Chinese
- ...

```

아래와 같은 구조로 변경하는 것이었습니다:

```plaintext
Food
- Featured

```

American, Chinese 등은 태그로 전환하고, 모든 고정된 주제는 Featured 하위 카테고리로 이동시킨 뒤 고정 해제했습니다.

```ruby
# 카테고리 내 모든 고정된 주제를 고정 해제하고 하위 카테고리로 이동
 def move_pinned_topics_to_subcategory(category, subcategory_name)
  subcategory = Category.where(name: subcategory_name).find_by(parent_category_id: category.id)
  topics = Topic.where(category_id: category.id).where.not(pinned_at: nil)
  topics.each do |topic|
    topic.update(pinned_at: nil, pinned_globally: false, pinned_until: nil,
      category_id: subcategory.id) if not topic.title[/About the .+ category/]
  end
  Category.update_stats
end

food_cat = Category.find_by(name: 'Food')
move_pinned_topics_to_subcategory(food_cat, 'Featured')

```

---

<div class="post-metadata">

### Author: ![shyguy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shyguy/32/295079_2.png) [@shyguy](https://meta.discourse.org/u/shyguy)
#### Post date: [3월 30, 2023, 10:28오후 UTC](https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374/24 "2023-03-30T22:28:46Z")

</div>

제 포럼에는 이전의, 폐쇄된 버전(이것도 phpBB)이 있었고, wget siterip으로 백업이 남아 있어서 이걸 위한 가져오기(importer)를 만들고 있습니다. nokogiri로 HTML 파일을 파싱해서 중간 DB에 넣고, 그다음 가져오기 베이스 클래스를 이용해 Discourse에 행을 삽입하는 방식입니다.

이것을 봤습니다:

> [@Import HTML site to Discourse?](https://meta.discourse.org/t/import-html-site-to-discourse/120474):
>
> Hey gang. Is there any way to import a “wget” scrape of an old forum? I would like to move it to Discourse, but I do not have the SQL file. Old forum is based on Xenforo. [This thread](https://meta.discourse.org/t/archive-an-old-forum-in-place-to-start-a-new-discourse-forum/13433) gives me hope

이건 드문 문제인 것 같은데, 다른 분들도 이 문제를 겪고 있다면 조금 더 다듬어서 공유해볼 수도 있겠습니다. 알려주세요.

혹시 이미 이걸 만들어서 공유해줄 사람이 있다면 그쪽이 더 좋습니다. 아직 프로젝트 초기 단계라 여유가 있습니다.

[Previous page](https://meta.discourse.org/t/my-phpbb-migration-journey-postgresql/259374.md?page=1)
