0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.js+TypeScript+Docker+Prismaのテーブル生成まで

Posted at

Next.js+TypeScript+DockerでPrismaのセットアップをする手順を備忘録として以下に記載します。

インストールと下準備

docker compose run --rm frontend sh
npm install @prisma/client
npm install prisma --save-dev
docker compose run --rm frontend sh
npx prisma init

Dockerfileに以下を追記してビルドします。

RUN npx prisma generate
prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

以下のようにoutputが記載されたままだと
generator client {
provider = "prisma-client-js"
output = "../generated/prisma"
}
以下のようなエラーが出る場合があります。
:::note warn
⨯ Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
:::

postgresのIPを固定します。

docker-compose.yml
  frontend:
  ・
  ・
  ・  
  postgres:
  ・
  ・
  ・
    networks:
      fixed_compose_network:

テーブルの生成

先にpostgresのコンテナだけを起動しmigrateをしてテーブルを生成します。

docker compose up postgres
docker compose run --rm frontend sh
npx prisma migrate dev --name init

なお、特定のコンテナだけを止めるときは以下のコマンドです。

docker-compose rm -fsv サービス名

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?