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?

tsxライブラリを入れよう

npm i tsx

必要なライブラリは以上です

prisma/seed.ts
import { PrismaClient } from "@prisma/client";

const db = new PrismaClient();
async function seed() {
  await db.user.create({
    data: {
      email: "[email protected]",
      password: "password",
    },
  });
}

seed()
  .catch(e => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await db.$disconnect();
  });

簡単なseedの追加です コレを書き換えてそれぞれの環境に合わせたものを作成してください

package.json
  + "type": "module",
   "scripts":{
  +  "seed" : "tsx ./prisma/seed.ts"
  +  }
  ----
  +"prisma": {
  +  "seed": "tsx ./prisma/seed.ts"
  +  }

prismaのseedの部分の追加をすることでmigrateするときに自動で実行されます

npm run seed

こうすることで手動で実行できるようになります

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?