-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- docker - mysql:8.0 - mysql-migration 사용 #1
- Loading branch information
Showing
11 changed files
with
332 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE DATABASE letters_chat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Oops, something went wrong.