fotoflo
fotoflo
Explore posts from servers
PPrisma
Created by fotoflo on 6/4/2024 in #help-and-questions
db push and migrate dev
i used prisma db push, and now i want to create the migration and push to prod. I used migrate dev on local and it wants me to delete all data. i assume later when i migrate prod i will also lose all data?
9 replies
PPrisma
Created by fotoflo on 5/14/2024 in #help-and-questions
Database Design for Sitemaps
No description
2 replies
PPrisma
Created by fotoflo on 4/19/2024 in #help-and-questions
How to get the type of a compound query?
how would i get the type of this?
ts
const commentsPromise = prisma.urlComments.findMany({
where: {
urlId,
},
include: {
User: {
select: {
name: true,
email: true,
image: true,
},
},
},
orderBy: {
createdAt: "desc",
},
});

const statusCheckPromise = prisma.statusChecks.findMany({
where: {
urlId,
httpCode: {
notIn: [200, 301, 302, 303, 307, 308],
},
},
orderBy: {
createdAt: "desc",
},
});

const [comments, statusChecks] = await prisma.$transaction([
commentsPromise,
statusCheckPromise,
]);
ts
const commentsPromise = prisma.urlComments.findMany({
where: {
urlId,
},
include: {
User: {
select: {
name: true,
email: true,
image: true,
},
},
},
orderBy: {
createdAt: "desc",
},
});

const statusCheckPromise = prisma.statusChecks.findMany({
where: {
urlId,
httpCode: {
notIn: [200, 301, 302, 303, 307, 308],
},
},
orderBy: {
createdAt: "desc",
},
});

const [comments, statusChecks] = await prisma.$transaction([
commentsPromise,
statusCheckPromise,
]);
6 replies
PPrisma
Created by fotoflo on 3/9/2024 in #help-and-questions
Fixing slow query
Hey guys, any idea why this query might suddenly take 9 seconds?
export async function getStatusChecks(urlId: string) {
console.time("getStatusChecks");

const millisInDay = 1000 * 60 * 60 * 24;
const result = await prisma.statusChecks.findMany({
where: {
urlId: { equals: urlId },
createdAt: { gte: new Date(Date.now() - 4 * millisInDay) },
},
orderBy: {
createdAt: "asc",
},
take: 50,
});

console.timeEnd("getStatusChecks");
return result;
}
export async function getStatusChecks(urlId: string) {
console.time("getStatusChecks");

const millisInDay = 1000 * 60 * 60 * 24;
const result = await prisma.statusChecks.findMany({
where: {
urlId: { equals: urlId },
createdAt: { gte: new Date(Date.now() - 4 * millisInDay) },
},
orderBy: {
createdAt: "asc",
},
take: 50,
});

console.timeEnd("getStatusChecks");
return result;
}
schema:
model statusChecks {
id String @id @default(cuid())
createdAt DateTime @default(now()) @db.Timestamp(0)
bodySize Int?
effectiveUrl String @db.VarChar(4096)
errorCode String?
httpCode Int?
httpCodeLang String?
redirectCount Int?
totalTime Decimal
status Boolean
urlId String @db.VarChar(25)
urls urls @relation(fields: [urlId], references: [id], onDelete: Cascade)
}
model statusChecks {
id String @id @default(cuid())
createdAt DateTime @default(now()) @db.Timestamp(0)
bodySize Int?
effectiveUrl String @db.VarChar(4096)
errorCode String?
httpCode Int?
httpCodeLang String?
redirectCount Int?
totalTime Decimal
status Boolean
urlId String @db.VarChar(25)
urls urls @relation(fields: [urlId], references: [id], onDelete: Cascade)
}
Maybe i need to add some indices?
11 replies