I am trying to apply seed data into supabase database from the Next.js 13 app that using appDir. In some tutorials and articles, you can place seed file in pages/api
and once it runs next api server, seed data would be applied. I want to try that, but the project built with Next.13 with appDir, it doesn't have pages
directory.
Project file structure
I tried to place seed file in app/api
instead of pages/api
, and run next api server, but it didn't work.
Also, I tried another way to apply seed which is to place seed.ts in prisma folder that has schema.prisma, and run npx prisma db seed
with the script and prisma settings like below:
package.json
{
"name": "next-learn",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"seed": "node prisma/seed.ts"
},
"dependencies": {
"@prisma/client": "4.12.0",
"@types/node": "^18.15.11",
"@types/react": "18.0.33",
"@types/react-dom": "18.0.11",
"autoprefixer": "10.4.14",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"next": "13.3.0",
"postcss": "8.4.21",
"prisma": "^4.12.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.1",
"typescript": "^5.0.4"
},
"devDependencies": {
"ts-node": "^10.9.1"
},
"prisma": {
"seed": "node --loader ts-node/esm prisma/seed.ts"
}
}
next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}
module.exports = nextConfig
I would be glad to learn how to apply seed in next.js 13 with appDir.