acidjazz
acidjazz
Explore posts from servers
PPrisma
Created by acidjazz on 8/25/2024 in #help-and-questions
Unique constraint fails when creating user(s)in parallel during tests for api endpoints
When I run tests in my app in parallel that have helpers that create users in the DB, i get this error:
FAIL ../test/cartridge.test.ts > /api/cartridge > post /api/cartridge - create a cartridge
PrismaClientKnownRequestError:
Invalid `prisma.user.upsert()` invocation:


Unique constraint failed on the constraint: `users_email_key`
❯ _n.handleRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7749
❯ _n.handleAndLogRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7057
❯ _n.request ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:6741
❯ l ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:130:9355
❯ Module.createUser utils/user.ts:11:10
9| let user: User | null = null
10|
11| user = await prisma.user.upsert({
| ^
12| where: { email: info.email },
13| create: {
❯ userFromEmail ../test/auth.ts:38:28
❯ Module.actingAs ../test/auth.ts:44:16
❯ ../test/cartridge.test.ts:12:28

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'P2002', clientVersion: '5.18.0', meta: { modelName: 'User', target: 'users_email_key' }, batchRequestIdx: undefined }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL ../test/cartridge.test.ts > /api/cartridge > post /api/cartridge - create a cartridge
PrismaClientKnownRequestError:
Invalid `prisma.user.upsert()` invocation:


Unique constraint failed on the constraint: `users_email_key`
❯ _n.handleRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7749
❯ _n.handleAndLogRequestError ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:7057
❯ _n.request ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:121:6741
❯ l ../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:130:9355
❯ Module.createUser utils/user.ts:11:10
9| let user: User | null = null
10|
11| user = await prisma.user.upsert({
| ^
12| where: { email: info.email },
13| create: {
❯ userFromEmail ../test/auth.ts:38:28
❯ Module.actingAs ../test/auth.ts:44:16
❯ ../test/cartridge.test.ts:12:28

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'P2002', clientVersion: '5.18.0', meta: { modelName: 'User', target: 'users_email_key' }, batchRequestIdx: undefined }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Although if i disable parallelism and only allow 1 thread this error never shows up.
1 replies
NNuxt
Created by acidjazz on 8/6/2024 in #❓・help
server api route catchall
is it possible to do something like this with one file? and not have to softlink?
❯ lss server/api/token
drwxr-xr-x k staff 128 B Sat Aug 3 23:19:51 2024  .
drwxr-xr-x k staff 288 B Sun Aug 4 01:11:30 2024  ..
.rw-r--r-- k staff 1.1 KB Sun Aug 4 04:01:22 2024  [...id].ts
lrwxr-xr-x k staff 10 B Sat Aug 3 23:19:51 2024  index.ts ⇒ [...id].ts
❯ lss server/api/token
drwxr-xr-x k staff 128 B Sat Aug 3 23:19:51 2024  .
drwxr-xr-x k staff 288 B Sun Aug 4 01:11:30 2024  ..
.rw-r--r-- k staff 1.1 KB Sun Aug 4 04:01:22 2024  [...id].ts
lrwxr-xr-x k staff 10 B Sat Aug 3 23:19:51 2024  index.ts ⇒ [...id].ts
1 replies
PPrisma
Created by acidjazz on 8/5/2024 in #help-and-questions
using prisma $extends to add fields to a model, whats the best practice for TS?
Below is how i add a custom "client" field to my tokens model - but now my Token model doesn't really match since there is no client field in that. What is the best practice for taking care of that?
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton().$extends({
name: 'tokenParser',
result: {
token: {
client: {
needs: {
agent: true,
},
compute({ agent }) {
return new UAParser(agent).getResult()
},
},
},
},
})
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton().$extends({
name: 'tokenParser',
result: {
token: {
client: {
needs: {
agent: true,
},
compute({ agent }) {
return new UAParser(agent).getResult()
},
},
},
},
})
6 replies
PPrisma
Created by acidjazz on 8/4/2024 in #help-and-questions
prisma client generates model with no create
model Session {
id Int @id @default(autoincrement())
userId Int
user User @relation(fields: [userId], references: [id])
token String @unique
ip String @default("127.0.0.1")
agent String @default("")
// coordinate Unsupported("Point")
coordinate String @default("30.2423 : -97.7672")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("sessions")
}
model Session {
id Int @id @default(autoincrement())
userId Int
user User @relation(fields: [userId], references: [id])
token String @unique
ip String @default("127.0.0.1")
agent String @default("")
// coordinate Unsupported("Point")
coordinate String @default("30.2423 : -97.7672")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("sessions")
}
can anyone tell me why i dont get a prisma.session.create ? Property 'create' does not exist on type 'SessionDelegate<DefaultArgs>'.ts(2339)
11 replies
NNuxt
Created by acidjazz on 1/19/2023 in #❓・help
layout logic failing
<doc-menu v-if="useRoute().name === 'doc-article'">
<slot />
</doc-menu>
<slot v-else />
<doc-menu v-if="useRoute().name === 'doc-article'">
<slot />
</doc-menu>
<slot v-else />
this generates JS errors and fires off the page vue component twice Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
5 replies