Skip to content

fix(db): ra_news 스키마 생성 마이그레이션 추가 - #935

Closed
stadia wants to merge 1 commit into
mainfrom
fix/933-create-ra-news-schema
Closed

stadia wants to merge 1 commit into
mainfrom
fix/933-create-ra-news-schema

Conversation

@stadia

@stadia stadia commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Closes #933

문제

config/database.yml:23schema_search_path: "ra_news,public" 이 지정돼 있지만, 리포지토리 어디에도 ra_news 스키마를 만드는 코드가 없었다.

$ grep -rn "ra_news\|create_schema\|CREATE SCHEMA" db/migrate/ lib/tasks/ config/initializers/
(결과 없음)

PostgreSQL 은 search_path 첫 항목이 존재하지 않으면 조용히 건너뛰고 다음 항목(public)에 객체를 만든다. ra_news 를 생성하는 유일한 코드는 gitignore 대상인 db/schema.rbcreate_schema 였으므로, 신규 클론에서 db:migrate 로 셋업하면 모든 테이블이 public 에 생성되어 프로덕션과 다른 레이아웃이 됐다.

변경

ra_news 스키마를 만드는 마이그레이션을 추가했다. 최초 스키마(20260330052834_init_schema)보다 앞선 타임스탬프(20260330052833)를 부여해 신규 환경에서 가장 먼저 실행되게 한다.

  • CREATE SCHEMA IF NOT EXISTS — 이미 스키마가 있는 환경(프로덕션 포함)에서는 무해하게 통과
  • down 은 의도적으로 no-op — 스키마를 지우면 내부 테이블이 전부 함께 사라져 init_schema 롤백보다 파괴적이다
  • PostgreSQL 이 아니거나 search_path 에 ra_news 가 없으면 아무것도 하지 않는다

검증

① 신규 환경 (스키마 없음 + schema.rb 없음) — 실제로 마이그레이션 46개가 실행되고 테이블이 ra_news 에 생성됨:

== 20260330052833 CreateRaNewsSchema: migrated
== 20260330052834 InitSchema: migrated
...
 schemaname | count
------------+-------
 public     |     2
 ra_news    |    29

변경 전 동일 절차에서는 29개 테이블이 전부 public 에 생성됐다.

② 기존 환경 (스키마·테이블 이미 존재)schema_migrations 에서 해당 버전만 지우고 재실행:

== 20260330052833 CreateRaNewsSchema: migrated (0.0007s)
 public  |  2
 ra_news | 29     ← 테이블 이동 없음

bundle exec rspec → 64 examples, 0 failures / rubocop → no offenses

남는 부분

public 에 남는 2개는 schema_migrationsar_internal_metadata 다. Rails 가 첫 마이그레이션 이전에 만들기 때문에 마이그레이션으로는 위치를 옮길 수 없다. 앱 동작에는 영향이 없어(search_path 로 해석됨) 이번 PR 범위에서는 두었다.

db:create 시점에 스키마를 만드는 rake 후크로 이것까지 맞출 수 있지만, 같은 일을 하는 두 번째 메커니즘이 생기고 rake 로드 순서 의존이 붙어서 뺐다. 필요하면 별도로 논의.

관련

🤖 Generated with Claude Code

https://claude.ai/code/session_012km6QF6Pd6N1dfoDifok1q

database.yml 에 schema_search_path: "ra_news,public" 이 지정돼 있으나
리포지토리 어디에도 ra_news 스키마를 만드는 코드가 없었다. PostgreSQL 은
search_path 에 없는 스키마를 건너뛰고 다음 항목(public)에 객체를 만들기
때문에, 신규 클론에서 db:migrate 로 셋업하면 모든 테이블이 public 에
생성되어 프로덕션(ra_news)과 다른 레이아웃이 됐다. ra_news 를 만드는
유일한 코드는 gitignore 대상인 db/schema.rb 의 create_schema 였다.

최초 스키마(20260330052834_init_schema)보다 앞선 타임스탬프를 부여해
신규 환경에서 가장 먼저 실행되게 하고, 이미 적용된 환경에서는
CREATE SCHEMA IF NOT EXISTS 로 무해하게 통과시킨다.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012km6QF6Pd6N1dfoDifok1q
@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@stadia, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 91 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0f0d11f-a0be-4191-adf0-bd4523c35ac1

📥 Commits

Reviewing files that changed from the base of the PR and between bd85157 and bf3dc13.

📒 Files selected for processing (1)
  • db/migrate/20260330052833_create_ra_news_schema.rb

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf3dc13c21

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

def up
return unless search_path_includes_schema?

execute("CREATE SCHEMA IF NOT EXISTS #{quote_schema}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 기존 public 전용 DB를 빈 ra_news 상태로 두지 마세요

이 수정 전 db:migrate로 초기화되어 애플리케이션 테이블이 모두 public에 있는 환경에서는 이 문장이 빈 ra_news 스키마만 만들고 기존 테이블은 이동하지 않습니다. 이후 schema_search_pathra_news,public이므로 기존 테이블은 계속 public에서 조회되지만 향후 create_table 마이그레이션은 ra_news에 생성되어 한 데이터베이스의 앱 객체가 두 스키마로 갈라집니다. 이 경우를 감지해 기존 객체를 옮기거나 안전하게 중단해야, 바로 이 결함으로 이미 만들어진 클론도 운영 레이아웃으로 수렴할 수 있습니다.

AGENTS.md reference: AGENTS.md:L171-L171

Useful? React with 👍 / 👎.

@stadia stadia closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

신규 환경에서 db:migrate 시 테이블이 ra_news 대신 public 스키마에 생성됨

1 participant