Skip to content

Commit

Permalink
chat DB 구축
Browse files Browse the repository at this point in the history
- docker
- mysql:8.0
- mysql-migration 사용

#1
  • Loading branch information
goo-gy committed May 25, 2022
1 parent a5c0294 commit d6819d8
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 3 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# Letters-Chat
Letter Chatting Server


# letters-graphQL

## env 설정

```
SECRET_KEY=[]
API_URL=[]
DB_HOST=[]
DB_user=[]
DB_password=[]
```

- JWT SECRET KEY 설정
- API URL 설정
- DB 정보 설정

---

## DB 설치 및 초기화

- Docker 설치 후

```shell
npm run db:init
npm run db:migrate
```


### migration 추가
``` shell
npx babel-node migration.js add migration [migration name]
```
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.0"
services:
chat_db:
container_name: letters_chat_db
build: ./docker
ports:
- "${DB_PORT}:3306"
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
1 change: 1 addition & 0 deletions docker/0_create_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE letters_chat
3 changes: 3 additions & 0 deletions docker/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mysql:8.0

COPY 0_create_db.sql /docker-entrypoint-initdb.d
18 changes: 18 additions & 0 deletions migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import mysql from 'mysql2';
import migration from 'mysql-migrations';

import dotenv from 'dotenv';
dotenv.config();

const { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD } = process.env;

const connection = mysql.createPool({
connectionLimit: 10,
host: DB_HOST,
port: DB_PORT,
user: DB_USER,
password: DB_PASSWORD,
database: 'letters_chat',
});

migration.init(connection, __dirname + '/migrations');
Loading

0 comments on commit d6819d8

Please sign in to comment.