Mischa
08/19/2022, 9:57 PMSakar SR
08/20/2022, 9:57 AMper
08/20/2022, 6:04 PMstring
and not a date
.
I know I can create a New Date()
on the frontend but my types are messing up because it’s set to Date
-type in the schema but it’s actually a string in my code. What is the correct way to handle this?Clément Guibout
08/20/2022, 6:13 PMVadzim Veleshka
08/20/2022, 7:28 PMVadzim Veleshka
08/20/2022, 7:28 PMTyler Clendenin
08/21/2022, 1:40 AMoptions?: { $transaction?: Prisma.TransactionClient | null }
and the line
const prisma = options?.$transaction ?? this.prisma
(where this.prisma
is the PrismaClient
injected into my object)
unfortunately Typescript seems to think prisma
is always the Prisma.TransactionClient
so I can't say if (typeof prisma.$transaction !== 'undefined')
to narrow the scope between what should be PrismaClient | Prisma.TransactionClient
Is there any better way to conditionally run a service method in a transaction?
secondary question. Is there a way given a Prisma.TransactionClient
that I can pass in Promises similar to how I can run prisma.$transaction([prisma.model.action(), prisma.model.action2()])
?
tertiary question, why does the Prisma.TransactionClient
not have it's own $transaction method? At the very least it could just use the currently open transaction, at best it could optionally do a nested transaction or savepointWilliam GM
08/21/2022, 2:33 AMQuery createOneshipment_entry is required to return data, but found no record(s).
Reference (https://github.com/prisma/prisma/issues/12783)Tyler Clendenin
08/21/2022, 2:46 AMwhere id IN (${Prisma.join(ids)})
where the id is a uuid, I get the error
Raw query failed. Code: `42883`. Message: `db error: ERROR: operator does not exist: uuid = text
what do I need to do to cast those correctly?William GM
08/21/2022, 5:11 AMRadostin Romanov
08/21/2022, 6:13 AMusers
. In there, I have id, email, password, createdAt
and so on. I soon realized that my users need roles as well, so, I created the roles
column where I was to add an array of roles (I would have a roles
table, connecting it all), but realized that MySQL doesn't(?) have support for arrays like that. I then settled on simply creating another table - userMeta
, where I simply store id, role
(where id
is the user's id), in here, multiple rows can have the same user id, but not the same role, so, if I had an user with an id 1
and I had 2 roles - administrator, user
, my usersMeta
table would look as follows:
id role
---------
1 administrator
1 user
In order for me to determine what roles an user has, I'd just simply run SELECT role from user_meta WHERE id=1
. While this works, I just don't feel this is the right way to do things. I don't want to store roles as JSON, because then I can't query everything freely based on roles an user has or whatever else.
Here are my current models:
enum Roles {
ADMIN
MODERATOR
USER
}
model User {
id Int @id @default(autoincrement())
username String @unique
email String @unique
firstName String @map("first_name")
lastName String @map("last_name")
createdAt DateTime @default(now()) @map("created_at")
}
model UserMeta {
id Int
role Roles @default(USER)
@@id([id, role])
}
model Role {
id Int @id
}
The database works, it's how I want it to be represented, I just don't know how to write it the "Prisma way". For example, right now, the id
in usersMeta
is any string. I'd like there to be a relation where that id can ONLY be an id from the User
model.Christophe Rudyj
08/21/2022, 1:18 PM// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>
// The Models have been standardized this way to remove any confusion
// in_ : denotes that it is in these related field ex: mtg is in_boxes
// _id : is a field that requires the id of an other table like : user_id
// _rel: This is prisma generated field
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Games {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
short_hand String @unique @db.VarChar(255)
name String @unique @db.VarChar(255)
in_boxes Box[]
in_sets Sets[]
vendor String @db.VarChar(255) @default("")
sealed String[] @db.VarChar(255)
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String @unique @db.VarChar(255)
password String @db.VarChar(255)
role Role @default(USER)
first_name String? @db.VarChar(255)
last_name String? @db.VarChar(255)
stores Store[]
}
model Store {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique @db.VarChar(255)
owner_id Int?
users_list User[]
boxes Box[]
}
model Box {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
set String @db.VarChar(255)
set_rel Sets @relation(fields: [set], references: [name])
box_number String @db.VarChar(100)
box_second_number String? @db.VarChar(100)
game_id Int? @default(1)
game_rel Games? @relation(fields: [game_id], references: [id])
store_id Int?
store_rel Store? @relation(fields: [store_id], references: [id])
}
model Sets {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique @db.VarChar(255)
code String? @db.VarChar(255)
game_id Int? @default(1)
game_rel Games? @relation(fields: [game_id], references: [id])
edition String?
children String[]
in_boxes Box[]
}
model Logs {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
store_id Int
user_id Int
action String @db.VarChar(255)
message String @db.VarChar(255)
}
enum Role {
USER
ADMIN
CHRIS}
Then here's the query i'm trying to do:
const set = await context.prisma.sets.findFirst({
where: {
AND: [
{
OR: [
{
name: {
contains: name,
mode: "insensitive",
},
},
{
code: {
contains: code,
mode: "insensitive",
},
},
],
},
{
in_boxes: {
every :{
store_id: {
equals: context.req.session.storeId,
}
}
}
}
],
},
select: {
id: true,
name: true,
code: true,
game_id: true,
children: true,
in_boxes: true,
}
});
I'm trying to return the set that contains either the name or the code but only return those set who are in the boxes who have that storeId (an Int)
The first way I've tried ids by getting all the boxes and then _`set?.in_boxes.filter((box: any) => box.store_id === context.req.session.storeId);` however I soon realised that the more Set request I will get the more slower this will go_
The other way is that i tried ataching the in_boxes to the OR statements however it never returns the right set
An other way i've though is to go with my box table to find the set via name or code however i think it would be too cumbersomeThomas Morice
08/21/2022, 4:53 PMnumber
. I basically want to filter from an input field, kind of like a contains
but for a number.. Is that something we can do by any chance?
Thanks in advance 🙂Jay Bell
08/21/2022, 9:08 PMPeter
08/22/2022, 12:22 AMconst update = await prisma.post.update({
where: {
id: 6,
},
data: {
author: {
upsert: {
create: {
email: '<mailto:bob@prisma.io|bob@prisma.io>',
name: 'Bob the New User',
},
update: {
email: '<mailto:bob@prisma.io|bob@prisma.io>',
name: 'Bob the existing user',
},
},
},
},
})
Robert Lee
08/22/2022, 1:06 AMJson[]
type or Json
and just shove in [{key:value}, ...]
into it? Ideally i'd like to be able to do jsonField.map((item) => ...)
in my code.Gustavo
08/22/2022, 2:12 AMCan't write to /application/node_modules/prisma please make sure you install "prisma" with the right permissions.
👀
package.json
dependencies: {
"@prisma/client": "^4.1.0",
},
devDepe {
"prisma": "^4.1.0"
}
Any ideas? 😬 thanks in advance 🙂
The error occurs when running the command:
npx prisma generate --schema=./path/to/file/prisma/schema.prisma
in logs I can see:
Prisma schema loaded from ./path/to/file/prisma/schema.prisma
Error: Can't write to /application/node_modules/prisma please make sure you install "prisma" with the right permissions.
KIM SEI HOON
08/22/2022, 2:16 AMInvalidDatasourceError: Datasource "db" references an environment variable "POSTGRE_DATABASE_URL" that is not set
An error occurs. My env value is like this.
<prisma://XXX.prisma-data.com/?api_key=XXX>
Prisma Enabled Version: 4.2.1
Prisma.schema is as follows.
datasource db {
provider = "postgresql"
url = env("POSTGRE_DATABASE_URL")
}
Is there a reason why this error occurs?Gustavo
08/22/2022, 2:42 AMGustavo
08/22/2022, 4:56 AMuser group permissions folder
myUser nogroup drwx-r-xr-x src
myUser nogroup drwx-r-xr-x node_modules/prisma
myUser nogroup drwx-r-xr-x node_modules/.prisma
myUser nogroup drwx-r-xr-x node_modules/@prisma
the api I have is executed by the user: `myUser`on startup, and it also runs a separated script as a child process to run migrations from, but i get the error:
Can't write to /application/node_modules/prisma please make sure you install "prisma" with the right permissions.
which makes me think I should add the w
permission to prisma folders?
RUN chmod -R o+w /application/node_modules/.prisma /application/node_modules/@prisma /application/node_modules/prisma
the script i'm using to run migrations looks like:
const cmd1 = spawnSync('npx', ['prisma', 'generate', `--schema=${prismaSchema}`]);
console.log('cmd1: ', cmd1.stdout.toString('utf8'), cmd1.stderr.toString('utf8'));
const cmd2 = spawnSync('npx', ['prisma', 'migrate', 'deploy', `--schema=${prismaSchema}`]);
console.log('cmd2: ', cmd2.stdout.toString('utf8'), cmd2.stderr.toString('utf8'));
Could someone guide me here? 😅
All of these is running in a ECS container, any help is highly appreciated 🙂sagar lama
08/22/2022, 8:53 AMmodel Product {
id Int @id @default(autoincrement())
name String?
fees Fee[] @relation("fees")
default_fee Fee? @relation("default_fee")
}
model Fee {
id Int @id @default(autoincrement())
total Float @default(0)
product_id Int
product Product @relation(name: "fees", fields: [product_id], references: [id], onDelete: Cascade)
defaultable Product? @relation(name: "default_fee", fields: [defaultable_id], references: [id])
defaultable_id Int? @unique
}
While fetching its works like expected.
However while creating product with nested relations like this:
const product = await this.prisma.product.create({
data: {
...data,
default_fee: {
create: {
// asks for product id
total: 500,
},
},
},
});
It asks me for product id. But it doesn't make sense to pass product_id as I wouldn't have the product id at that point.
I know I can make it work by breaking the query down, but nested create doesnot seem to work for disambiguating relations. I'm curious wether it's issue on prisma or I'm missing something here
Repo Link: https://github.com/sagarPakhrin/prisma-disambiguating-relations/blob/master/src/app.service.tsSebastian Gug
08/22/2022, 9:40 PMtelmo
08/23/2022, 9:02 AMPeter
08/23/2022, 9:38 AMmodel Domain {
id String @id @default(cuid())
domain String @unique
majesticDomainData MajesticDomainData?
}
model MajesticDomainData {
id String @id @default(cuid())
domain Domain @relation(fields: [domainId], references: [id])
domainId String @unique
topics MajesticTopicalData[]
}
model MajesticTopicalTrustFlow {
id String @id @default(cuid())
topic String @unique
domainData MajesticTopicalData[]
}
model MajesticTopicalData {
domainData MajesticDomainData @relation(fields: [domainDataId], references: [id])
domainDataId String
topicalTrustFlow MajesticTopicalTrustFlow @relation(fields: [topicalTrustFlowId], references: [id])
topicalTrustFlowId String
topicalPercent Decimal @db.Decimal(5, 4)
@@id([domainDataId, topicalTrustFlowId])
}
prisma.domain.update({
where: {<http://asd.com|asd.com>},
data: {
majesticDomainData: {
create: {
topics: {
create: [
{
topic: 'health',
topicalPercent: 0.24
},
{
topic: 'rec',
topicalPercent: 0.33
},
]
},
}
}
},
})
+ topicalTrustFlow: {
+ create?: MajesticTopicalTrustFlowCreateWithoutDomainInput | MajesticTopicalTrustFlowUncheckedCreateWithoutDomainInput,
+ connectOrCreate?: MajesticTopicalTrustFlowCreateOrConnectWithoutDomainInput,
+ connect?: MajesticTopicalTrustFlowWhereUniqueInput
+ }
Im not sure if im connecting the many to many relationship correctly, its asking for my explicit tableGustavo
08/23/2022, 9:39 AMDATABASE_URL
which is working fine for migrations, but now for seeding i'm unsure how to proceed 🤔
In my script I tried running:
const seeds = spawnSync('npx', ['ts-node', './src/package/package_1/prisma/seed.ts']);
but i get the error:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './seed.ts'
Require stack:
- /application/src/packages/package_1/prisma/imaginaryUncacheableRequireResolveScript
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.resolve (node:internal/modules/cjs/helpers:108:19)
at requireResolveNonCached (/application/node_modules/ts-node/dist/bin.js:549:16)
at getProjectSearchDir (/application/node_modules/ts-node/dist/bin.js:519:40)
at phase3 (/application/node_modules/ts-node/dist/bin.js:267:27)
at bootstrap (/application/node_modules/ts-node/dist/bin.js:47:30)
at main (/application/node_modules/ts-node/dist/bin.js:33:12)
at Object.<anonymous> (/application/node_modules/ts-node/dist/bin.js:579:5)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/application/src/packages/package_1/prisma/imaginaryUncacheableRequireResolveScript'
]
}
Any ideas? 😄 Thanks in advance 🙂Nurul
08/23/2022, 10:08 AM@prisma
folder in node_modules?Michael Roberts
08/23/2022, 10:14 AMFishie
08/23/2022, 10:32 AMprisma.user.updateMany
and disconnect a list using data: {discoonect: {id: 1}}
?Ignatius Hefer
08/23/2022, 11:24 AMSlackbot
08/23/2022, 11:36 AM