Next.js

[Next.js] Planet Scale + Prisma ๋ฐฐํฌํ•˜๊ธฐ (Vercel)

lheunoia 2022. 10. 18. 19:20

 

 

๐Ÿš€  ํ”„๋กœ์ ํŠธ ๋ฐฐํฌํ•˜๊ธฐ

๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•˜๋˜ DB์™€ ๋ฐฐํฌ ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•  DB๋ฅผ ํ˜ผ์šฉํ•˜์ง€ ์•Š๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ”„๋กœ์ ํŠธ ๊ฐœ๋ฐœ ์‹œ์— ๋งŒ๋“  DB branch๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ง€๊ธˆ๋ถ€ํ„ฐ branch ๋ฐฐํฌ ๋ฐฉ๋ฒ•์„ ํ•œ ๋‹จ๊ณ„์”ฉ ์•Œ์•„๊ฐ€ ๋ด…์‹œ๋‹ค. (๊ธ€์“ด์ด๋Š” Vercel๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐฐํฌํ–ˆ์Šต๋‹ˆ๋‹ค.)

 

 

 

 

 

 

 

1. Promote branch

https://app.planetscale.com/

 

Sign in - PlanetScale

 

auth.planetscale.com

์šฐ์„  PlanetScale ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•ด ๋กœ๊ทธ์ธ ํ›„, main branch์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค. 

 

 

 

 

 

Promote a branch to production ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด main branch๊ฐ€ production์œผ๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

 

 

 

 

2. Add Environment Variables

 

๋ฐฐํฌํ•œ ํ”„๋กœ์ ํŠธ๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ”„๋กœ์ ํŠธ์˜ .env ํŒŒ์ผ์—์„œ ์ž‘์„ฑํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋“ค์„ ๋ฐฐํฌํ•œ ํ”„๋กœ์ ํŠธ์—๋„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•˜๋Š”๋ฐ์š”.

 

 

 

์šฐ์„  ๋ฐฐํฌํ•œ DB์™€ ๋‚ด ํ”„๋กœ์ ํŠธ๋ฅผ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” DATABASE_URL์„ ํ•„์ˆ˜์ ์œผ๋กœ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. PlanetScale ์‚ฌ์ดํŠธ์—์„œ ๋ฐฐํฌํ•œ branch์— ์ ‘์†ํ•˜์—ฌ connect ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์œ„์™€ ๊ฐ™์€ ํŒ์—…์ฐฝ์ด ๋œจ๊ณ  .env ํƒญ์—์„œ DATABASE_URL ๊ฐ’์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด ๊ฐ’์€ ์ดˆ๊ธฐ 1ํšŒ๋งŒ password๊ฐ€ ๋ณด์ด๊ธฐ ๋•Œ๋ฌธ์— ์ž˜ ๋ณต์‚ฌํ•ด ๋‘์—ˆ๋‹ค๊ฐ€ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ์ถ”๊ฐ€ํ•˜๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์‹ค์ˆ˜๋กœ ์ฐฝ์„ ๋‹ซ๊ฑฐ๋‚˜ ๋ณต์‚ฌํ•ด ๋‘์ง€ ๋ชปํ–ˆ๋‹ค๋ฉด ์šฐ์ธก ์ค‘์•™์— New password ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ƒˆ๋กœ ๋ฐœ๊ธ‰๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. :)

 

 

 

 

 

 

https://vercel.com/

 

Vercel: Develop. Preview. Ship. For the best frontend teams

Vercel is the platform for frontend developers, providing the speed and reliability innovators need to create at the moment of inspiration.

vercel.com

 

 

์ด์ œ Vercel ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ช… > settings > Environment Variables ์ˆœ์œผ๋กœ ๋“ค์–ด๊ฐ€๋ฉด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

NAME ๋ž€์— .env ํŒŒ์ผ์—์„œ ์ž‘์„ฑํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜์˜ ํ‚ค๋ฅผ, VALUE ๋ž€์—๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜์˜ ํ‚ค ๊ฐ’์„ ์ž…๋ ฅํ•ด์ฃผ๊ณ  Add ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค.

 

 

 

 

 

3. Redeploy project

 

 

ํ”„๋กœ์ ํŠธ์— ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์œผ๋ฉด ํ”„๋กœ์ ํŠธ๋ฅผ ๋‹ค์‹œ ๋ฐฐํฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Deployment ํƒญ์—์„œ ๋”๋ณด๊ธฐ ๋ž€์„ ํด๋ฆญํ•œ ๋’ค Redeploy ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ํ”„๋กœ์ ํŠธ๊ฐ€ ๋‹ค์‹œ ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ๋ฐฐํฌ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ๋˜๋ฉด ์˜ค๋ฅธ์ชฝ Visit ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. โ˜บ๏ธ

 

 

 

 

 

 

4. Create New branch

๊ธฐ์กด์— ์‚ฌ์šฉํ•˜๋˜ main branch๋Š” ๋ฐฐํฌ์šฉ branch๊ฐ€ ๋๊ธฐ ๋•Œ๋ฌธ์— ๋” ์ด์ƒ ๊ฐœ๋ฐœ์šฉ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š”๋ฐ์š”. ๊ฐœ๋ฐœ์šฉ DB๋ฅผ ์ƒ์„ฑํ•˜๋ ค๋ฉด PlanetScale ์‚ฌ์ดํŠธ์—์„œ New branch ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•œ ํ›„ ํ”„๋กœ์ ํŠธ ํ„ฐ๋ฏธ๋„์—์„œ pscale connect DB๋ช… branch๋ช…์„ ์ž…๋ ฅํ•˜๋ฉด ๋ฐฉ๊ธˆ ์ „์— ์ƒ์„ฑํ•œ branch๋ฅผ ๊ฐœ๋ฐœ์šฉ branch๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

 

 

 

 

 

 

 

 

์ด๋ฏธ ๋ฐฐํฌํ•œ DB์˜ ์Šคํ‚ค๋งˆ๋ฅผ ์ˆ˜์ •ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ์š”?

๊ทธ ํ•ด๋‹ต์€ ๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ ๋‹ค๋ฃจ์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๋ฐ˜์‘ํ˜•