Skip to content

데이터베이스 구성 및 엔트리포인트 개선#28

Open
eajnoeyeel wants to merge 1 commit into
mainfrom
fix/database-configuration
Open

데이터베이스 구성 및 엔트리포인트 개선#28
eajnoeyeel wants to merge 1 commit into
mainfrom
fix/database-configuration

Conversation

@eajnoeyeel

@eajnoeyeel eajnoeyeel commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

📌 변경 내용 요약

  • 기존에 공통으로 사용하던 환경 변수를 Chat 서비스 전용 환경 변수(DB_CHAT_NAME, DB_CHAT_USER, DB_CHAT_PASSWORD)로 분리했습니다.
  • Chat 서비스는 전용 데이터베이스(chat_db) 에만 연결됩니다.
  • 엔트리포인트 스크립트에서 자동 마이그레이션을 비활성화하여 시작 시 크래시 문제를 해결했습니다.
  • 마이그레이션은 데이터베이스 연결 확인 후 수동으로 실행하도록 변경했습니다.

🔗 관련 이슈

💡 주요 변경 사항

  • config/settings.py: 서비스별 DB 환경 변수로 변경
    • POSTGRES_DBDB_CHAT_NAME
    • POSTGRES_USERDB_CHAT_USER
    • POSTGRES_PASSWORDDB_CHAT_PASSWORD
  • utils/entrypoint.sh: 자동 마이그레이션 비활성화 (주석 처리)
    • python manage.py makemigrations 주석 처리
    • python manage.py migrate 주석 처리
  • 서비스 간 데이터베이스 충돌 방지
  • 시작 시 크래시 문제 해결

🧩 리뷰어 참고 사항

  • .env 파일의 값이 변경되었으므로, 로컬 환경에서 테스트 시 .env를 새로 적용해야 합니다.
  • 기존 데이터(mydatabase)는 더 이상 사용하지 않으며, chat_db 데이터베이스가 생성됩니다.
  • 데이터베이스 및 사용자 생성 필요:
    docker exec database_chat psql -U myuser -d postgres -c "CREATE DATABASE chat_db OWNER myuser;"
    docker exec database_chat psql -U myuser -d postgres -c "CREATE USER chat_user WITH PASSWORD 'chat_pass';"
    docker exec database_chat psql -U myuser -d chat_db -c "GRANT ALL ON SCHEMA public TO chat_user;"
  • 마이그레이션은 다음 명령으로 수동 실행:
    docker exec chat python manage.py migrate

✅ 테스트 방법

  1. Chat 서비스가 정상적으로 시작되는지 확인:

    docker-compose up chat
    docker ps | grep chat
    # 예상: 컨테이너가 Running 상태
  2. 데이터베이스 연결 확인:

    docker exec chat python manage.py shell -c "from django.conf import settings; print(settings.DATABASES['default']['NAME'])"
    # 예상 출력: chat_db

- Changed from generic POSTGRES_DB/USER/PASSWORD to DB_CHAT_NAME/USER/PASSWORD
- Ensures chat service connects to its own database (chat_db)
- Disabled automatic migrations in entrypoint to prevent startup crashes
- Migrations should be run manually after verifying database connectivity
- Part of microservices database isolation improvements
Copilot AI review requested due to automatic review settings October 31, 2025 08:54

Copilot AI left a comment

Copy link
Copy Markdown

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 database configuration environment variables and comments out automatic migrations during container startup.

  • Renamed database environment variables from POSTGRES_* to DB_CHAT_* naming convention
  • Commented out automatic Django migrations in the entrypoint script

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
config/settings.py Updates PostgreSQL database configuration to use DB_CHAT_NAME, DB_CHAT_USER, and DB_CHAT_PASSWORD environment variables instead of POSTGRES_* variants
utils/entrypoint.sh Comments out automatic execution of Django migrations during container startup

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

Comment thread config/settings.py
Comment on lines 89 to 90
'HOST': config('POSTGRES_HOST', default='localhost'),
'PORT': config('POSTGRES_PORT', default='5432'),

Copilot AI Oct 31, 2025

Copy link

Choose a reason for hiding this comment

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

Inconsistent naming convention for database environment variables. While NAME, USER, and PASSWORD now use the DB_CHAT_* prefix, HOST and PORT still use the POSTGRES_* prefix. Consider renaming POSTGRES_HOST to DB_CHAT_HOST and POSTGRES_PORT to DB_CHAT_PORT for consistency.

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

Copilot uses AI. Check for mistakes.
@eajnoeyeel eajnoeyeel changed the title 🐛 fix: 데이터베이스 구성 및 엔트리포인트 개선 데이터베이스 구성 및 엔트리포인트 개선 Oct 31, 2025
Comment thread config/settings.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

각 디비별로 독립적인 env를 사용하는건 원래 목표와 부합하여 좋은 변경이네요

Comment thread utils/entrypoint.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

해당 로직 자체의 문제보단 기존에 디비 컨테이너가 제대로 실행 및 연결이 되지 않아서 발생한 문제 같아 보이네요.
거기에 해당 파일의 상단에 보면 running 중인지 확인하는 로직이 있는데 해당 로직도 제대로 동작하지 않는다고 보여집니다.
결국 근본적인 원인인 postgre 실행 및 연결 문제를 해결하는 것이 급선무라고 판단됩니다.

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] 데이터베이스 구성 문제 및 시작 시 크래시

3 participants