Repository navigation
chore: 코드베이스 초기 설정 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
d841b46
8812b4c
827223f
f679a6c
bd9a4f8
ce90973
c32753d
2ba5527
d8dcee8
ff0c219
597feaa
bfc0636
b89cea1
7644102
0cdec55
48ba064
780ae78
b372322
eebc98e
c5671d2
3bd3c53
f3552ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| NODE_ENV=development | ||
| PORT=3000 | ||
| DATABASE_URL=postgres://postgres:postgres@localhost:5432/team_mino | ||
| DB_POOL_SIZE=10 | ||
|
|
||
| POSTGRES_HOST=localhost | ||
| POSTGRES_PORT=5432 | ||
| POSTGRES_USER=postgres | ||
| POSTGRES_PASSWORD=postgres | ||
| POSTGRES_DB=team_mino | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| dist/ | ||
| node_modules/ | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
| !.env.*.example | ||
| [._]*.s[a-v][a-z] | ||
| [._]*.sw[a-p] | ||
| [._]s[a-rt-v][a-z] | ||
| [._]ss[a-gi-z] | ||
| [._]sw[a-p] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Team MINO Node | ||
|
|
||
| NestJS 기반 Team MINO 백엔드 API 서버입니다. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Bun 1.3.x | ||
| - Docker | ||
|
|
||
| ## Setup Guide | ||
|
|
||
| ### 1. Install Dependencies | ||
|
|
||
| ```bash | ||
| bun install | ||
| ``` | ||
|
|
||
| ### 2. Configure Environment | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| 기본 로컬 DB 연결 정보는 아래 값입니다. | ||
|
|
||
| ```env | ||
| DATABASE_URL=postgres://postgres:postgres@localhost:5432/team_mino | ||
| ``` | ||
|
|
||
| ### 3. Start Local Database | ||
|
|
||
| ```bash | ||
| docker compose up -d postgres | ||
| ``` | ||
|
|
||
| 컨테이너 상태를 확인합니다. | ||
|
|
||
| ```bash | ||
| docker compose ps | ||
| ``` | ||
|
|
||
| ### 4. Start Development Server | ||
|
|
||
| ```bash | ||
| bun run start:dev | ||
| ``` | ||
|
|
||
| 서버 기본 포트는 `3000`입니다. | ||
|
|
||
| ```text | ||
| http://localhost:3000 | ||
| ``` | ||
|
|
||
| ### 5. Check Health API | ||
|
|
||
| ```bash | ||
| curl http://localhost:3000/health | ||
| ``` | ||
|
|
||
| 정상 응답은 아래와 같습니다. | ||
|
|
||
| ```json | ||
| { | ||
| "status": "ok" | ||
| } | ||
| ``` | ||
|
|
||
| ## Available Scripts | ||
|
|
||
| ```bash | ||
| bun run start:dev | ||
| bun run build | ||
| bun run check | ||
| bun run lint | ||
| bun run format | ||
| bun run test | ||
| ``` | ||
|
|
||
| ## API Docs | ||
|
|
||
| 개발 서버 실행 후 Swagger 문서는 아래 경로에서 확인할 수 있습니다. | ||
|
|
||
| ```text | ||
| http://localhost:3000/api-docs | ||
| ``` | ||
|
|
||
| ## Database | ||
|
|
||
| 로컬 PostgreSQL은 Docker Compose로 실행합니다. | ||
|
|
||
| ```bash | ||
| docker compose up -d postgres | ||
| docker compose down | ||
| ``` | ||
|
|
||
| Drizzle 설정은 `drizzle.config.ts`를 사용합니다. | ||
|
|
||
| ```bash | ||
| bun run db:generate | ||
| bun run db:migrate | ||
| bun run db:push | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "$schema": "https://biomejs.dev/schemas/2.4.15/schema.json", | ||
| "files": { | ||
| "includes": ["**", "!dist", "!node_modules"] | ||
| }, | ||
| "formatter": { | ||
| "enabled": true, | ||
| "indentStyle": "space", | ||
| "indentWidth": 2 | ||
| }, | ||
| "assist": { | ||
| "actions": { | ||
| "source": { | ||
| "organizeImports": "on" | ||
| } | ||
| } | ||
| }, | ||
| "linter": { | ||
| "enabled": true, | ||
| "rules": { | ||
| "recommended": true, | ||
| "style": { | ||
| "useImportType": "off" | ||
| } | ||
| } | ||
| } | ||
| } |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||
| services: | ||||||||||
| postgres: | ||||||||||
| image: postgres:18-alpine | ||||||||||
| container_name: team-mino-postgres | ||||||||||
| restart: unless-stopped | ||||||||||
| ports: | ||||||||||
| - "${POSTGRES_PORT:-5432}:5432" | ||||||||||
| environment: | ||||||||||
| POSTGRES_USER: ${POSTGRES_USER:-postgres} | ||||||||||
| POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} | ||||||||||
| POSTGRES_DB: ${POSTGRES_DB:-team_mino} | ||||||||||
| volumes: | ||||||||||
| - postgres_data:/var/lib/postgresql/data | ||||||||||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: No, mounting a volume at /var/lib/postgresql/data does not persist data in the way it did in previous versions for PostgreSQL 18 and newer [1][2]. In PostgreSQL 18+, the official Docker image structure has changed significantly [1][2]: 1. Changed Data Location: The default data directory (PGDATA) is now located at /var/lib/postgresql/18/docker [3][2]. 2. Volume Mount Point: The VOLUME directive in the Dockerfile has been moved from /var/lib/postgresql/data to /var/lib/postgresql [2]. 3. No Compatibility Symlink: While there was an initial attempt to include a compatibility symlink, it was explicitly removed in the Alpine images (and others) to avoid issues [4]. If you attempt to mount a volume at /var/lib/postgresql/data, it will generally be ignored or result in an unused mount point, because the container expects the data to reside within the /var/lib/postgresql directory structure [1][3]. Recommended Configuration: To ensure data persists correctly in PostgreSQL 18+, you should mount your volume at the parent directory: volumes: - my_db_data:/var/lib/postgresql This configuration allows PostgreSQL to place its data in the correct version-specific subdirectory (e.g., /var/lib/postgresql/18/docker), which is essential for proper functionality and future upgrades using tools like pg_upgrade [1][3]. If you persist in using the old mount path, you may encounter silent data loss where the container initializes a new database in an anonymous volume while ignoring your existing data on the host [3]. Citations:
PostgreSQL 18용 볼륨 마운트 경로를 현재 권장 예시 volumes:
- - postgres_data:/var/lib/postgresql/data
+ - postgres_data:/var/lib/postgresql이전 리뷰에서 언급된 대로 compose를(KKardy가) 별도로 정비할 때 함께 반영해 주세요. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| healthcheck: | ||||||||||
| test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] | ||||||||||
| interval: 5s | ||||||||||
| timeout: 5s | ||||||||||
| retries: 5 | ||||||||||
|
|
||||||||||
| volumes: | ||||||||||
| postgres_data: | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||||||||
| import { defineConfig } from "drizzle-kit"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const databaseUrl = process.env.DATABASE_URL; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (!databaseUrl) { | ||||||||||||||||||||||||||||||||||
| throw new Error("DATABASE_URL is required"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
빈 값만 막고 있어서 오타 URL이 들어오면 이후 단계에서 에러가 납니다. 여기서 즉시 검증하면 원인 파악이 쉬워집니다. 수정 예시 const databaseUrl = process.env.DATABASE_URL;
if (!databaseUrl) {
throw new Error("DATABASE_URL is required");
}
+
+try {
+ new URL(databaseUrl);
+} catch {
+ throw new Error("DATABASE_URL must be a valid URL");
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export default defineConfig({ | ||||||||||||||||||||||||||||||||||
| schema: "./src/database/schema/index.ts", | ||||||||||||||||||||||||||||||||||
| out: "./drizzle", | ||||||||||||||||||||||||||||||||||
| dialect: "postgresql", | ||||||||||||||||||||||||||||||||||
| dbCredentials: { | ||||||||||||||||||||||||||||||||||
| url: databaseUrl, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
디비 풀 기본값은 Supabase 환경 고려해서 수정이 필요할 수도 있는거죠?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supabase PgBouncer 사용한다면 풀은 1~2로 줄일게요!