Chris Valentine
Chris Valentine
PPrisma
Created by Chris Valentine on 12/8/2024 in #help-and-questions
v6 Migration Doesn't Work
I did a baseline for my current db in prisma 5. all in sync, all good. I think updated prisma and @prisma/client to v6 then i ran npx prisma migrate dev --name upgrade-to-v6 and it says my database is out of sync with my schema and it has shifted. it lists all the things that are wrong with it That list of wrong issues only contains the implicit index changes from v6. It then says in order to run this i must lose all data??? has to be a way to do this without losing all data? as a note my usual method of adding to adn removing from the database are: npx prisma generate npx prisma push
17 replies
PPrisma
Created by Chris Valentine on 9/26/2024 in #help-and-questions
Property does not exist on type..but it clearly does.
No description
4 replies
PPrisma
Created by Chris Valentine on 5/2/2024 in #help-and-questions
I feel this is simple but I fear i've just been at it too long I'm starting to not see straight.
I have a parent record with a many to many relationship with a child, such as:
model User {
id String @id @default(cuid())
name String?
username String? @unique

badges UserBadges[]
}

model Badge {
id String @id @default(cuid())
name String @unique
users UserBadges[]
}

model UserBadges {
id String @id @default(cuid())
userId String
badgeId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
badge Badge @relation(fields: [badgeId], references: [id], onDelete: Cascade)
}
model User {
id String @id @default(cuid())
name String?
username String? @unique

badges UserBadges[]
}

model Badge {
id String @id @default(cuid())
name String @unique
users UserBadges[]
}

model UserBadges {
id String @id @default(cuid())
userId String
badgeId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
badge Badge @relation(fields: [badgeId], references: [id], onDelete: Cascade)
}
i want to insert (or upsert). a new User. for that user i will have a list of badges by name only, i will not know the id of them at that point, but they are sure to already exist in the DB.
const user = await prisma.user.upsert({
where: {email: userRecord.email},
update: {
username: userRecord.username,
name: userRecord.name,
badges: {
connect: {
id: userRecord.badges.map((badge: any) => {
return {name: badge.name}
})
}
}
},
create: {
username: userRecord.username,
name: userRecord.name,
badges: userRecord.badges,
}
})
const user = await prisma.user.upsert({
where: {email: userRecord.email},
update: {
username: userRecord.username,
name: userRecord.name,
badges: {
connect: {
id: userRecord.badges.map((badge: any) => {
return {name: badge.name}
})
}
}
},
create: {
username: userRecord.username,
name: userRecord.name,
badges: userRecord.badges,
}
})
around here typescript just yells at me. How do I get this working and connect them by name instead of id?
1 replies