ludovic
01/20/2022, 12:48 PMAlex Vilchis
01/20/2022, 5:02 PMSean Huggins
01/21/2022, 6:40 AMSean Huggins
01/21/2022, 6:43 AMca:*
-> cat, car, can, Canada, cats, catastrophic, etc....)Sean Huggins
01/21/2022, 6:44 AMSean Huggins
01/21/2022, 6:44 AMSean Huggins
01/21/2022, 6:44 AM.prisma
schema file is so prettyKi Hong
01/21/2022, 7:06 AMmodel PostLevel {
postLevelCode String
countryCode String
languageCode String
postLevelName String
@@id([postLevelCode, countryCode, languageCode])
@@unique([postLevelCode, countryCode, languageCode])
}
model Profile {
id String @id
countryCode String
user User?
}
model User {
id String @id
languageCode String
profileId String
profile Profile @relation(fields: [profileId], references: [id])
posts Post[]
}
model Post {
id String @id
postedById String
postedBy User @relation(fields: [postedById], references: [id])
postLevelCode String
postLevel PostLevel @relation(fields: [postLevelCode], references: [postLevelCode, countryCode, languageCode])
}
I want to be able to resolve postLevelName
when I query Post
. **ps: This is an existing and production DB where DB migration should be avoided at all cost.
This can be solved by using $queryRaw
and INNER JOIN
but that would defeat the purpose of using this great ORM.
Im getting these errors:Sean Huggins
01/21/2022, 8:22 AMuser
01/21/2022, 11:19 AMShmuel
01/21/2022, 4:17 PMconst update = await prisma.user.update({
where: {
id: 6,
},
data: {
posts: {
updateMany: {
where: {
published: true,
},
data: {
published: false,
},
},
},
},
})
In this case all posts that match the where clause will be updated to published: false
I would like to know if it's possible to do an updateMany
without passing a where
clause. Rather passing in a bunch of objects to the data
property and prisma will know which records to update based on the unique key which will be in each object. Like this...
const update = await prisma.user.update({
where: {
id: 6,
},
data: {
posts: {
updateMany: {
data: [
{ id: 5, published: false }, { id: 6, published: true }
],
},
},
},
})
Yaakov
01/21/2022, 5:48 PMUser
and InternalUserProfile
only when User.type = INTERNAL
.
model User {
id Int @id @default(autoincrement())
type UserType
internalUserProfile InternalUserProfile?
}
model InternalUserProfile {
user User @relation(fields: [userId = User.id AND User.type = 'INTERNAL'], references: [id])
userId Int
}
enum UserType {
INTERNAL
EXTERNAL
}
Simon BrÀnnström
01/21/2022, 6:05 PMAlex Vilchis
01/21/2022, 6:21 PMAndy Bustamante
01/21/2022, 9:08 PMcontext.prisma.model.upsert({
where: { id: undefined },
update: args.data,
create: args.data,
})
maxd
01/22/2022, 1:15 AMmaxd
01/22/2022, 1:17 AM{"error":{"clientVersion":"3.5.0"}}
Kelly Copley
01/22/2022, 3:52 AMNull constraint violation on the (not available)
. I'm not sure why it says (not available)
or what that means.. As far as I can tell there isn't anything null within the object passed to the create method. Schema is as follows:
model User {
id String @id @default(uuid())
email String? @unique
emailVerified DateTime?
isPresenter Boolean @default(false)
bio String? @db.LongText
cellPhone String?
homePhone String?
firstName String?
middleName String?
lastName String?
permissions Permission[]
street String?
unit String?
city String?
state State?
zip String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tickets Ticket[]
sessions Session[]
orders Order[]
}
And the code for the upsert:
const user = await prisma.user.upsert({
where: { email: '<mailto:your.email+fakedata47684@gmail.com|your.email+fakedata47684@gmail.com>' },
update: {},
create: {
email: '<mailto:your.email+fakedata47684@gmail.com|your.email+fakedata47684@gmail.com>',
firstName: 'Stan',
lastName: 'Schamberger',
street: '2100 Maymie Bridge',
city: 'Stromanport',
state: 'OR',
zip: '17083'
}
});
As you can see every field in the schema besides relation fields, is either optional or have defaults set, which makes me wonder which constraint is failing.Zhen
01/22/2022, 4:37 AM"prismaLayer\nodejs\node_modules\.prisma\libquery_engine-rhel-openssl-1.0.x.so.node"
"Error: Query engine library for current platform \"rhel-openssl-1.0.x\" could not be found.",
"You incorrectly pinned it to rhel-openssl-1.0.x",
"",
"This probably happens, because you built Prisma Client on a different platform.",
"(Prisma Client looked in \"/var/task/src/libquery_engine-rhel-openssl-1.0.x.so.node\")",
"",
"Searched Locations:",
"",
" /.prisma/client",
" /home/runner/work/.../node_modules/@prisma/client",
" /var/task",
" /var/task/node_modules/.prisma/client",
" /var/task/node_modules/.prisma/client",
" /tmp/prisma-engines",
" /var/task/node_modules/.prisma/client",
"",
"You already added the platform \"rhel-openssl-1.0.x\" to the \"generator\" block",
"in the \"schema.prisma\" file as described in <https://pris.ly/d/client-generator>,",
"but something went wrong. That's suboptimal.",
"",
Zhen
01/22/2022, 4:37 AMjames milord
01/22/2022, 6:38 AMcustomers
and stores
which I define in my schema.prisma
file like this
model Customer {
id BigInt @id @default(autoincrement())
email String @db.VarChar(255)
encrypted_password String
first_name String? @default("") @db.VarChar(255)
last_name String? @default("") @db.VarChar(255)
reset_password_sent_at DateTime?
reset_password_token String? @db.VarChar(16)
status CustomerStatus @default(ACTIVE)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
store Store @relation(fields: [store_id], references: [id])
store_id BigInt
@@index([email, store_id])
@@index([reset_password_token])
@@index([email])
@@index([store_id])
@@map("customers")
}
model Store {
id BigInt @id @default(autoincrement())
customer Customer[]
domain String @default("") @db.VarChar(255)
locale Locale @default(US)
region String? @db.VarChar(255)
sender String @default("") @db.VarChar(255)
shopify_store_name String? @db.VarChar(255)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
@@map("stores")
}
enum CustomerStatus {
ACTIVE @map("active")
ACTIVATING @map("activating")
}
enum Locale {
US @map("en-US")
UK @map("en-GB")
}
after running npx prisma migrate dev --name <migration name>
I get the following sql migration migration file output
/*
Warnings:
- You are about to drop the `customer` table. If the table is not empty, all the data it contains will be lost.
*/
-- CreateEnum
CREATE TYPE "CustomerStatus" AS ENUM ('active', 'activating');
-- CreateEnum
CREATE TYPE "Locale" AS ENUM ('en-US', 'en-GB');
-- DropTable
DROP TABLE "customer";
-- CreateTable
CREATE TABLE "customers" (
"id" BIGSERIAL NOT NULL,
"email" VARCHAR(255) NOT NULL,
"encrypted_password" TEXT NOT NULL,
"first_name" VARCHAR(255) DEFAULT E'',
"last_name" VARCHAR(255) DEFAULT E'',
"reset_password_sent_at" TIMESTAMP(3),
"reset_password_token" VARCHAR(16),
"status" "CustomerStatus" NOT NULL DEFAULT E'active',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"store_id" BIGINT NOT NULL,
CONSTRAINT "customers_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "stores" (
"id" BIGSERIAL NOT NULL,
"domain" VARCHAR(255) NOT NULL DEFAULT E'',
"locale" "Locale" NOT NULL DEFAULT E'en-US',
"region" VARCHAR(255),
"sender" VARCHAR(255) NOT NULL DEFAULT E'',
"shopify_store_name" VARCHAR(255),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "stores_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "customers_email_store_id_idx" ON "customers"("email", "store_id");
-- CreateIndex
CREATE INDEX "customers_reset_password_token_idx" ON "customers"("reset_password_token");
-- CreateIndex
CREATE INDEX "customers_email_idx" ON "customers"("email");
-- CreateIndex
CREATE INDEX "customers_store_id_idx" ON "customers"("store_id");
I was looking for the foreign key store_id
on the customers
table to have a constraint clause like the following
CONSTRAINT FOREIGN KEY ("store_id") REFERENCES "public"."stores" (id)
I have been unsuccessful so far and all I want is for the store_id
to be a foreign key that references the store id
.Kelly Copley
01/22/2022, 7:31 AMQuery interpretation error. Error for binding '6': Error occurred during query execution:
InterpretationError("Unable to convert expression result into a set of selection results", None)
Any help appreciated.Raj Chaudhary
01/22/2022, 12:29 PMDan Shapir
01/22/2022, 2:06 PMShoki I
01/22/2022, 3:32 PMFirst Model
Model A
 id
 name
 email
 description
 value1
 value2
 value3
â
Updated Model
Model A
 id
 name
Model B
 modelA_id
 modelB_id
 value
Model C
 id
 description
 label
Tomer Aberbach
01/22/2022, 5:00 PMexport async function findUserByEmailAndPassword<
Select extends Prisma.UserSelect,
>({ email, password }: UserData, select: Subset<Select, Prisma.UserSelect>) {
const user = await findUserByEmail(email, { ...select, passwordHash: true })
if (!user) {
return null
}
const { passwordHash, ...userWithoutPasswordHash } = user
if (!(await compareHash(password, passwordHash))) {
return null
}
return userWithoutPasswordHash
}
type Subset<T, U> = {
[Key in keyof T]: Key extends keyof U ? T[Key] : never
}
But no matter what I do TypeScript complains that user
does not have a passwordHash
property. I found https://github.com/prisma/prisma/issues/3372, which seems like it might be related, but I didn't see anything in there about how to handle the case of merging a select object provided by arguments with some additional fields (i.e. { ...select, passwordHash: true }
).
Any ideas?face boy
01/22/2022, 9:12 PMface boy
01/22/2022, 9:15 PMDatasource "db": PostgreSQL database "sampletext", schema "public" at "loremipsum thisisntactuallythetextfromtheerror",
No migration found in prisma/migrations
Error: P3005
The database schema for `some string of database characters` is not empty. Read more about how to baseline an existing production database: <https://pris.ly/d/migrate-baseline>
face boy
01/22/2022, 9:16 PMRich Starkie
01/22/2022, 9:20 PM