Skip to content

Conversation

@eajnoeyeel
Copy link
Collaborator

@eajnoeyeel eajnoeyeel commented Oct 31, 2025

📌 변경 내용 요약

  • 기존에 공통으로 사용하던 환경 변수(POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD)를
    각 서비스 전용 환경 변수(DB_USER_NAME, DB_USER_USER, DB_USER_PASSWORD)로 분리했습니다.
  • 이제 User 서비스는 전용 데이터베이스(user_db) 에만 연결되며,
    모든 서비스가 같은 DB(mydatabase)를 공유하던 문제를 해결했습니다.
  • 이 변경은 마이크로서비스 간 데이터베이스 격리 개선 작업의 일부입니다.

🔗 관련 이슈

💡 주요 변경 사항

  • config/settings.py에서 서비스별 DB 환경 변수로 변경
    • POSTGRES_DBDB_USER_NAME
    • POSTGRES_USERDB_USER_USER
    • POSTGRES_PASSWORDDB_USER_PASSWORD
  • 서비스 간 데이터베이스 충돌 방지
  • 마이크로서비스 아키텍처 내 데이터 독립성 확보

🧩 리뷰어 참고 사항

  • .env 파일의 값이 변경되었으므로, 로컬 환경에서 테스트 시 .env를 새로 적용해야 합니다.
  • 기존 데이터(mydatabase)는 더 이상 사용하지 않으며, 각 서비스별 신규 DB가 생성됩니다.
  • 데이터베이스 및 사용자 생성 필요:
    docker exec database_user psql -U myuser -d postgres -c "CREATE DATABASE user_db OWNER myuser;"
    docker exec database_user psql -U myuser -d postgres -c "CREATE USER user_user WITH PASSWORD 'user_pass';"
    docker exec database_user psql -U myuser -d user_db -c "GRANT ALL ON SCHEMA public TO user_user;"
  • 관련 마이그레이션 명령어:
    docker exec user python manage.py migrate

✅ 테스트 방법

  1. 각 서비스가 올바른 데이터베이스에 연결되는지 확인:

    docker exec user python manage.py shell -c "from django.conf import settings; print(settings.DATABASES['default']['NAME'])"
    # 예상 출력: user_db
  2. Nickname check API 테스트:

    curl -X POST http://localhost/api/user/register/nickname-check/ \
      -H "Content-Type: application/json" \
      -d '{"nickname":"testuser"}'
    # 예상 응답: {"message":"ok"}

- Changed from generic POSTGRES_DB/USER/PASSWORD to DB_USER_NAME/USER/PASSWORD
- Ensures user service connects to its own database (user_db) instead of shared mydatabase
- Fixes issue where all services were connecting to the same database
- Part of microservices database isolation improvements
Copilot AI review requested due to automatic review settings October 31, 2025 08:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates Django database configuration settings and uncomments the ALLOWED_HOSTS setting. The changes modify environment variable names for database credentials from POSTGRES_* to DB_USER_* prefixes.

  • Uncomments the ALLOWED_HOSTS setting to enable allowed host validation
  • Renames database configuration environment variables from POSTGRES_* to DB_USER_* naming convention

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 91 to 92
'HOST': config('POSTGRES_HOST', default='localhost'),
'PORT': config('POSTGRES_PORT', default='5432'),
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

The database configuration is inconsistent: credential variables use 'DB_USER_' prefix while HOST and PORT still use 'POSTGRES_' prefix (lines 91-92). This inconsistency makes configuration management confusing. Either all variables should use the 'DB_USER_' pattern or all should use 'POSTGRES_' for consistency.

Suggested change
'HOST': config('POSTGRES_HOST', default='localhost'),
'PORT': config('POSTGRES_PORT', default='5432'),
'HOST': config('DB_USER_HOST', default='localhost'),
'PORT': config('DB_USER_PORT', default='5432'),

Copilot uses AI. Check for mistakes.
@eajnoeyeel eajnoeyeel changed the title 🐛 fix: 서비스별 데이터베이스 환경 변수 적용 서비스별 데이터베이스 환경 변수 적용 Oct 31, 2025
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.

[BUG] 공통 데이터베이스에 연결되는 문제

2 participants