Knex

Migration Script ๋งŒ๋“ค๊ธฐ

knex๊ฐ€ ์„ค์น˜๋œ ์ƒํƒœ์—์„œ package.json์— ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

{
  // ...
  "scripts": {
    //...
    "db:migrate": "knex --esm migrate:latest",
    "db:migrate:make": "knex --esm migrate:make",
    //...
  },
  // ...
}
  • --esm : ES Module interlopability

npm run db:migrate:make migration-script-name ์„ ํ•˜๋ฉด ํ˜„์žฌ ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ์„ ์ ‘๋‘์‚ฌ๋กœ ํ•ด์„œ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค.

  • exports.up - ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์„ ์‹คํ–‰ํ•  ๊ฒฝ์šฐ ์‹คํ–‰ํ•  ํ•จ์ˆ˜

  • exports.down - ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์„ ๋กค๋ฐฑํ•  ๊ฒฝ์šฐ ์‹คํ–‰ํ•  ํ•จ

Last updated