Prisma is not working while deployed on Vercel with Vercel Postgresql but working in Development.
Here is my schema:
Here is the updatePageViews function:
Here is the scripts:
There is now error in the vercel log as well. Any help or suggestion will be appriciated. Thank you.
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
model Post {
id Int @id @default(autoincrement())
slug String @unique
title String
category String
view_count Int @default(1)
updatedAt DateTime @default(now())
}
model Subscribers {
id Int @id @default(autoincrement())
email String @unique
is_subscribed Boolean @default(true)
}
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
model Post {
id Int @id @default(autoincrement())
slug String @unique
title String
category String
view_count Int @default(1)
updatedAt DateTime @default(now())
}
model Subscribers {
id Int @id @default(autoincrement())
email String @unique
is_subscribed Boolean @default(true)
}
export async function updatePageViews(
postSlug: string,
title: string,
category: string
) {
try {
const existingPost = await db.post.findUnique({
where: { slug: postSlug },
});
if (existingPost) {
await db.post.update({
where: { slug: postSlug },
data: {
view_count: { increment: 1 },
},
});
} else {
await db.post.create({
data: {
slug: postSlug,
title: title,
category: category,
},
});
}
} catch (error) {
console.error("Error updating page view:", error);
}
}
export async function updatePageViews(
postSlug: string,
title: string,
category: string
) {
try {
const existingPost = await db.post.findUnique({
where: { slug: postSlug },
});
if (existingPost) {
await db.post.update({
where: { slug: postSlug },
data: {
view_count: { increment: 1 },
},
});
} else {
await db.post.create({
data: {
slug: postSlug,
title: title,
category: category,
},
});
}
} catch (error) {
console.error("Error updating page view:", error);
}
}
"scripts": {
"dev": "next dev",
"build": "next build",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"postinstall": "prisma generate",
"start": "next start",
"lint": "next lint"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"postinstall": "prisma generate",
"start": "next start",
"lint": "next lint"
},
0 Replies