Ruslan Gonzalez
02/05/2022, 3:11 PMRuslan Gonzalez
02/05/2022, 3:12 PMRuslan Gonzalez
02/05/2022, 3:12 PMLevi Mason
02/05/2022, 6:32 PMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// -------------------------------------- //
enum Role {
NONE
GROUP
MANAGER
}
enum ProjectStatus {
TEMPLATE
IN_PROGRESS
COMPLETED
}
enum TaskStatus {
IDLE
DOING
DONE
}
// -------------------------------------- //
model User {
id Int @id @default(autoincrement())
name String
email String @unique
role Role
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projects Project[]
Group Group? @relation(fields: [groupId], references: [id])
groupId Int?
}
model Group {
id Int @id @default(autoincrement())
name String
email String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
members User[]
projects Project[]
Manager Manager? @relation(fields: [managerId], references: [id])
managerId Int?
}
model Manager {
id Int @id @default(autoincrement())
userId String @unique
name String
email String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
groups Group[]
}
// -------------------------------------- //
model Project {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectStatus ProjectStatus
archived Boolean @default(false)
starred Boolean @default(false)
name String
description String
tag String
deadline DateTime
links String[]
stories Story[]
User User? @relation(fields: [userId], references: [id])
userId Int?
Group Group? @relation(fields: [groupId], references: [id])
groupId Int?
}
model Story {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
description String
tasks Task[]
Project Project? @relation(fields: [projectId], references: [id])
projectId Int?
}
model Task {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
status TaskStatus
Story Story? @relation(fields: [storyId], references: [id])
storyId Int?
}
ezeikel
02/06/2022, 12:12 AMfindMany
query and some
operator:
When running this query:
const clusters = await prisma.cluster.findMany({
where: {
followers: { some: { id: userId } },
},
});
I get this error:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "Command failed (Location40081): $in requires an array as a second argument, found: objectId)" } })
The two related models look like this:
model Cluster {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
name String
description String?
sparks Spark[] @relation(fields: [sparkIDs])
sparkIDs String[] @db.Array(ObjectId)
user User @relation("ClusterOwner", fields: [ownerID], references: [id])
ownerID String @db.ObjectId
shared Boolean @default(false)
deleted Boolean @default(false)
followers User[] @relation("ClusterFollowers", fields: [followerIDs])
followerIDs String[] @db.Array(ObjectId)
legacyId String? @unique
meta Meta[] @relation(fields: [metaIDs])
metaIDs String[] @db.Array(ObjectId)
log Log[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([ownerID, id])
@@map("clusters")
}
model User {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
firstName String?
lastName String?
name String?
email String @unique // TODO: doesnt seem to be being enforced
type UserType @default(EXTERNAL_SEA_USER)
pin String @default("0000")
role UserRole @default(USER)
deleted Boolean @default(false)
legacyId String? @unique
clusterFollowers Cluster[] @relation("ClusterFollowers")
clusterOwner Cluster[] @relation("ClusterOwner")
processedForUser Log[] @relation("ProcessedForUser")
processedByUser Log[] @relation("ProcessedByUser")
sparks Spark[]
subscriptions Subscription[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("users")
}
Any ideas on what I might be doing wrong or is this a bug with the mongo connector?Philipp Minder
02/06/2022, 10:48 PMFergus Meiklejohn
02/07/2022, 3:36 AMexport function removeNull(obj: any): any {
if (!obj) return obj;
if (obj instanceof Date) return obj;
else {
return Object.fromEntries(
Object.entries(obj)
.filter(([_, v]) => v != null)
.map(([k, v]) => [k, v === Object(v) ? removeNull(v) : v])
);
}
}
And before I added the instanceof check it was removing all Date types from the response because JS types Date as an object 🤪
The result was returning objects with {insertedAt: {} ... }
Maybe I'm missing a native Prisma method to remove nulls from queries??Fergus Meiklejohn
02/07/2022, 4:08 AM{0: {}, 1: {}, 2: {} etc...}
Has there been discussion about returning an array instead? An array would be more useful than an object whose keys are just the position in an array anyway. We can get the array with Object.values I know but still it seems like an unnecessary step..Miqhtie
02/07/2022, 5:49 AMEthan Zoller
02/07/2022, 6:32 AMJannik Schmiedl
02/07/2022, 7:18 AMGreger gregerson
02/07/2022, 2:56 PMMaotora
02/07/2022, 3:19 PMTag {
contents Content[]
name String @unique
}
Would need to order tag which has most content first.Maguire Krist
02/07/2022, 4:12 PMrelation: { connect: [ { id: num }, ...]}
Maguire Krist
02/07/2022, 4:31 PMMaguire Krist
02/07/2022, 4:31 PMMaguire Krist
02/07/2022, 4:32 PMMichael Aubry
02/07/2022, 5:27 PMid String @id @default(cuid())
I have a special case where I need to generate the record using an id I generate. Is it possible to pass a custom id into prisma.model.create
?Shayne Czyzewski
02/07/2022, 6:44 PMmigrate dev
after upgrading, it wants to create a new migration on existing SQLite and PostgreSQL databases. For SQLite, it wants to recreate all my tables (by creating a new migration basically with -- RedefineTables
and -- RedefineIndex
). For PostgreSQL, it does -- DropForeignKey
, -- AddForeignKey
, and -- RenameIndex
(that I have seen so far).
My main question is, is this expected and I should just add the new migration when upgrading (vs some other approach)? Any other tips/considerations to help migrate existing databases between these major versions? I did see this: https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-3 Thanks!user
02/07/2022, 7:54 PMNick B
02/08/2022, 12:37 AMPeter Kellner
02/08/2022, 12:42 AMmodel DiscussionItem {
Id Int @id(map: "PK__Discussi__3214EC0771E234E0") @default(autoincrement())
DiscussionId Int
AttendeesId Int
DateEntered DateTime @db.DateTime
MessageText String @db.NVarChar(4000)
Attendees Attendees @relation(fields: [AttendeesId], references: [Id], onUpdate: NoAction, map: "DiscussionItem_fk")
}
The real hassle is that all of the schema begins with uppercase "I" and I want those properties to translate easily to camelcase on the ApolloServer side. That is, id, attendeesId, discussionId, etc.
The issue is the accepted norm for database columns is begin with capital, the accept norm for JavaScript variables is begin with lowercase.
Is there an option for that?Sabin Adams
02/08/2022, 1:10 AMPeter Kellner
02/08/2022, 1:41 AMPeter Kellner
02/08/2022, 1:51 AMSabin Adams
02/08/2022, 2:13 AMSabin Adams
02/08/2022, 2:14 AMUsers
table, I would fix the conventions in that model as part of the PRSabin Adams
02/08/2022, 2:14 AMSabin Adams
02/08/2022, 2:27 AMUser
model for the first time. It might look like
model users {
Id Int @id @default(autoincrement())
first_name String
last_name String
}
I'd switch it to
model User {
id Int @id @default(autoincrement()) @map("Id")
firstName String @map("first_name")
lastName String @map("last_name")
@@map("users")
}
Sophia
02/08/2022, 4:21 AM'_http_common'
issue? I see a lot of issues on GitHub (and mentions in search here), but haven't found a solution yet. Thanks. ☺️