alexwasik
06/28/2022, 6:50 PMschema.prisma
I'm now getting this erroralexwasik
06/28/2022, 6:51 PMError parsing attribute "default": The 'autoincrement()' default function is defined only on BigInt fields on CockroachDB. Use sequence() if you want an autoincrementing Int field.
alexwasik
06/28/2022, 6:52 PMautoincrement
. Is this an error in the documentation?Danny SMc
06/28/2022, 6:53 PMDanny SMc
06/28/2022, 6:54 PMJames Johnson III
06/28/2022, 7:00 PMalexwasik
06/28/2022, 7:26 PMnpx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": CockroachDB database "undefined", schema "public" at "localhost:26257"
Error: P1000: Authentication failed against database server at `localhost`, the provided database credentials for `(not available)` are not valid.
Please make sure to provide valid database credentials for the database server at `localhost`.
alexwasik
06/28/2022, 7:26 PMAdam
06/28/2022, 7:49 PMSchalk Neethling
06/28/2022, 9:54 PMPieter
06/28/2022, 10:04 PMAmgelo563
06/29/2022, 2:00 AMgte
or lte
or what I should input thereChris Tsongas
06/29/2022, 4:49 AMyashvant
06/29/2022, 11:41 AMalexwasik
06/29/2022, 12:02 PMThe following migration(s) have been created and applied from new schema changes:
migrations/
└─ 20220629115129_init/
└─ migration.sql
Your database is now in sync with your schema.
Running generate... (Use --skip-generate to skip the generators)
Error: Get DMMF: Schema parsing - Error while interacting with query-engine-node-api library
Error code: P1012
error: Datasource provider not known: "cockroachdb".
--> schema.prisma:6
|
5 | datasource db {
6 | provider = "cockroachdb"
|
Validation Error Count: 1
alexwasik
06/29/2022, 12:11 PMnpx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: Get DMMF: Schema parsing - Error while interacting with query-engine-node-api library
Error code: P1012
error: Datasource provider not known: "cockroachdb".
--> schema.prisma:6
|
5 | datasource db {
6 | provider = "cockroachdb"
|
Validation Error Count: 1
Prisma CLI Version : 4.0.0
alexwasik
06/29/2022, 12:15 PM@prisma/client
is also 4.0.0
🤦Shahid Mawji
06/29/2022, 2:15 PMmodel ServiceMembership {
service Service @relation(fields: [serviceId], references: [serviceId])
serviceId Int @map("service_id")
membership Membership @relation(fields: [membershipId], references: [membershipId], onDelete: Cascade)
membershipId Int @map("membership_id")
assignedAt DateTime @default(now()) @map("assigned_at")
prices Price[]
@@id([serviceId, membershipId])
@@map(name: "service_membership")
}
I'd like to reference the ServiceMembership from the Price table. I can make it work by having a single referenced column in ServiceMembership but would prefer if I can use the existing composite ID (which it doesn't seem to support atm)
model Price {
priceId Int @id @default(autoincrement()) @map("price_id")
serviceMembership ServiceMembership @relation(fields: [serviceMembershipId], references: [serviceId, membershipId])
serviceMembershipId Int @map("service_membership_id")
יעקב
06/29/2022, 4:47 PMprisma db seed
into the dbTakeo Kusama
06/29/2022, 6:00 PMselect
ra.company_id as company_id,
ra.user_id as user_id,
from companies as cs
join users as us on cs.id = us.company_id
where
user.score >= ${score}
${replacableCondition}
;
In current, my codes have many similar sql scripts for sql injection protection like above except for writing raw query in ${replacableCondition} position.nonissue
06/29/2022, 10:12 PM@unique
attribute (in my case, I'm using PostgreSQL). Basically, I understand how it works, but I think that the documentation/tutorials are in a way misleading, and could cause serious potential issues for a lot of users.
The docs / tutorials frequently show examples were @unique
is added to model fields as a constraint. This makes perfect sense for some most of Prisma's data types, but the thing that concerns me is when it is shown being used to enforce a unique constraint on String
types, like emails and usernames. PostgreSQL uses deterministic collation by default, so filtering is case-sensitive by default.
Yes, Prisma does offer case-insensitive filtering using mode
, but I think a lot of people are going to set up their databases and not realize that, using just the @unique
attribute, a user could sign up with <mailto:ceo@corp.com|ceo@corp.com>
and another person could sign up with <mailto:CeO@corp.com|CeO@corp.com>
, etc. I can't think of a single use case where you wouldn't want a string field for emails to be constrained in a case-sensitive way. Or a user could sign up with jack
and another one could sign up with jaCk
, etc.
I understand that this is by design, and users can do things like enabling citext
in PostgreSQL, or they could write client side logic to do a case-insensitive search for an existing user during sign up (This one in particular seems very brittle and not a very robust solution). The big issue to me is that the documentation doesn't seem to communicate that this very important implementational detail needs to be handled by the user themselves*.
I'm not an expert with SQL or Prisma, so I'm fully aware I could be missing something, or I may have misunderstood how some of this works. Apologies in advance if that's the case.
\: I'm fully aware that there are Prisma docs on case-sensitivity, case-insensitive filtering, and even ones that even mention citext
, but I don't think they are easy to find, and they aren't referred to in many of the tutorials/examples/guides.*David Ilizarov
06/30/2022, 1:37 AMDavid Ilizarov
06/30/2022, 1:38 AMOvidiu Bodea
06/30/2022, 5:02 AMconst types = [
'model1',
'model2',
] as const;
return client[field].findMany({
where: {
verified: true,
},
});
The code works but TypeScript doesn’t like it
error TS2349: This expression is not callable.
Each member of the union type '(<T extends SkillTagFindManyArgs>(args?: SelectSubset<T, SkillTagFindManyArgs>) => CheckSelect<T, PrismaPromise<SkillTag[]>, PrismaPromise<...>>) | ... 4 more ... | (<T extends InterestFindManyArgs>(args?: SelectSubset<...>) => CheckSelect<...>)' has signatures, but none of those signatures are compatible with each other.
Any ideas? Thank youKay Khan
06/30/2022, 8:57 AMbrands
and join the image
table on image_id
.
const options = {
image: {
select: {
id: true,
source: true,
dtype: true,
},
},
}
const brands = await PrismaService.brand.findMany(options);
brands
has a return type of brand[]
you can see it does not include the image
relationship.
export type brand = {
id: string
name: string | null
image_id: string | null
created_at: Date | null
updated_at: Date | null
deleted_at: Date | null
}
Therefore b.image
throws a ts error Property 'image' does not exist on type 'brand'.
brands.forEach((b) => console.log(b.image))
Dog
06/30/2022, 1:38 PMalexwasik
06/30/2022, 1:58 PMMoin Akhter
06/30/2022, 1:59 PMAmgelo563
06/30/2022, 5:01 PMUnique constraint failed on the constraint
con a prisma.model.create({ someRow: { connect: id } })
where a record with the specified id does indeed exist?