Jose
10/12/2022, 7:43 PMmodel Account {
id String @id @default(uuid())
name String
billingAddress Address? @relation("billingAddress", fields: [billingAddressId], references: [id])
billingAddressId String?
fulfillmentAddress Address? @relation("fulfillmentAddress", fields: [fulfillmentAddressId], references: [id])
fulfillmentAddressId String?
addresses Address[]
}
model Address {
id String @id @default(uuid())
name String
accountBillingAddress Account[] @relation("billingAddress")
accountFulfillmentAddress Account[] @relation("fulfillmentAddress")
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
accountId String
@@unique([name, accountId])
}
I'm trying to seed a database creating and connecting the Account with Addresses (an Account could have many addresses, but 2 of them are quite special and marked as billing
and fulfillment
addresses:
{
id: '1',
name: 'Catalog',
addresses: {
create: [
{
id: 'Catalog-HQ',
name: 'Headquarters',
},
{
name: 'Miami Office',
},
],
},
billingAddressId: {
connect: { name: 'Headquarters' },
},
fulfillmentAddress: {
connect: { name: 'Miami Office' },
},
}
I'm getting an error
Unknown arg `name` in data.fulfillmentAddress.connect.name for type AddressWhereUniqueInput. Did you mean `id`? Available args:
type AddressWhereUniqueInput {
id?: String
name_accountId?: AddressNameAccountIdCompoundUniqueInput
}
which I'm suspecting is somehow related to the @@unique([name, accountId])
on the addresses (but also seems necessary in order not to repeat names on the same account). Any clue about what's wrong?abdoaligomaa107
10/13/2022, 5:52 AMJohn Carl Edcel Manuel
10/13/2022, 5:57 AM_<_td _className=_"py-4 pl-3"_>_
_{service.added_date} -> {dayjs(service.added_date).format(_"MMM D, YYYY h:mm A"_)}_
_</_td_>_
prisma
_added_date_ DateTime _@default_(now())
Nurul
10/13/2022, 6:32 AM4.4.0
and check if you get the same error?David Ilizarov
10/13/2022, 10:17 AMupdateMany
but with unique data per row...
I'm beginning to think this isn't possible with that API. Should I instead be using upsert
API for this?David Ilizarov
10/13/2022, 10:33 AMprisma.$transaction
Richard Jones
10/13/2022, 10:55 AMKay Khan
10/13/2022, 11:42 AMnpx prisma db pull
command?Andrea Romanello
10/13/2022, 4:39 PMTy-Lucas Kelley
10/13/2022, 5:14 PMprisma migrate
- was looking around for an option to do a 'dry run' of a migration before it's deployed, but didn't come across anything. Our goal is to be able to validate a migration in development against our production database(s) before that code is ever merged and deployed, so we don't have to wait for it to fail, then go through the process of rolling it back, editing the migration, re-deploying, etc..Hayley Dawson
10/13/2022, 6:19 PMSebastian Gug
10/13/2022, 8:24 PMDavid Ilizarov
10/13/2022, 8:32 PMcreateMany
while one of the fields is like a counter?
For example, I need something like this:
prisma.invoice.createMany({
data: [
{
name: invoice.name,
billerId: user.id,
invoiceNumber: prisma.invoice.count({where: { billerId: user.id }}) + 1
},
...
]
})
Perhaps there is a way for me to get all prisma.invoice.counts easily first.
prisma.invoice.groupBy({
by: ['billerId'],
_count: true
})
From there, I could smartly create the invoiceNumber...
I'd probably perform this in an interactive transaction.
My only problem is that during this groupBy/createMany combo, I want to ensure that the tables remained locked or that I can assure the actions are atomic — I don't want invoices created that would invalidate the invoiceNumber (as I have a unique constraint on [billerId, invoiceNumber])
Does something like the following suffice for that?
prisma.$transaction(async (tx) => {
const invoiceCountsForBiller = await tx.invoice.groupBy({
by: ['billerId'],
_count: true
})
await tx.invoice.createMany({
data: {[
{
// ... incorporate invoiceCountsForBiller into logic
}
]}
})
})
Amos Bastian
10/13/2022, 10:11 PMEntry
to Campaign
. I want to find all entries connected to a given campaign. I thought I could just do
const entries = await ctx.prisma.entry.findMany({
where: {
campaigns: { every: { id: { equals: campaignId } } },
},
});
but this is returning entries that aren’t connected to any campaigns as well 😕
According to the docs this should only return every Entry
that has a Campaign
with the given id, or am I wrong? I can solve this by adding some: {}
to the filter (to exclude every Entry
without a Campaign
, but this seems unnecessary to me)David Ilizarov
10/13/2022, 10:23 PMDavid Ilizarov
10/13/2022, 11:28 PMlet details: JsonValue | Prisma.DbNull = Prisma.DbNull;
// object.details is JsonValue
object.details = details === Prisma.DbNull ? null : details;
// Error: Type 'JsonValue | DbNull' is not assignable to type 'JsonValue'.
// Type 'DbNull' is not assignable to type 'JsonValue'
I don't see Prisma acknowledging this in documentation anywhere.
object.details = details instanceof Prisma.NullTypes.DbNull ? null : details;
// This works ^^^
Not sure I like the version that works for TypeScript. Thoughts?João Vitor Casarin
10/14/2022, 12:24 PMcreate
method does not explicitly throw an error in the Docs, but update
and delete
does. The method findFirst
has a second option that’s findFirstOrThrow
. Why aren’t all of these standardized, like making all of them throw an error when failed? That would be better for using I guess.Satish
10/14/2022, 12:49 PMJay Bensal
10/14/2022, 6:40 PMnpx prisma db push
to generate a schema against a local MySQL database running in a docker container. I’m getting a no database selected error… which is a bit odd to me, esp given that this exact command was working a week ago. any thoughts on how I can specify a db?
jay@Jays-Macbook-Air beam % npx prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "readyset_beam" at "127.0.0.1:3307"
Error: No database selected
0: sql_migration_connector::sql_database_step_applier::apply_migration
at migration-engine/connectors/sql-migration-connector/src/sql_database_step_applier.rs:11
1: migration_core::state::SchemaPush
at migration-engine/core/src/state.rs:274
AJ Holloway
10/14/2022, 10:54 PMconst scorers = await DBConn.recognition_logger.groupBy({
by: ['receiver_id'],
_sum: {
amount: true,
},
orderBy: {
_sum: { amount: 'desc' },
},
where: {
OR: [{ action: 'gave_points' }, { action: 'approve_claimable_award' }, { action: 'custom_award_send' }],
users_recognition_logger_receiver_idTousers: {
active: true,
},
amount: { gt: 0 },
company_id: res.locals.requestingUser.companies.id,
created: {
gte: DateTime.now().startOf('month').startOf('day').toUnixInteger(),
lte: DateTime.now().endOf('month').endOf('day').toUnixInteger(),
},
hidden_from_leaderboard: false,
valid: true,
type: {
equals: 'Regular',
},
},
});
scorers.map(async (e) => {
const user = await DBConn.users.findUnique({ where: { id: e.receiver_id } });
console.log(user);
});
receiver_id is a user’s id.
SELECT [*] FROM "public"."users" WHERE "public"."users"."id" IN ($1,$2) OFFSET $3
Params: [157359532448138,165341040401209,0]
Duration: 11ms
null
null
Interestingly, when I copy this into pgAdmin, it works just fine. Any idea why this is happening? Apologies for the long message, I removed all the fields for security and length’s sake. (Yes I know that I’m mapping and it returns a new object. But the output from the Query in my console is null,null)prisma chobo
10/14/2022, 11:07 PM"\nInvalid `prisma.user.findUnique()` invocation:\n\n\nQuery engine library for current platform \"darwin-arm64\" could not be found.
prisma chobo
10/14/2022, 11:08 PMprisma chobo
10/14/2022, 11:08 PMprisma chobo
10/14/2022, 11:10 PMbindaryTargets = ["native", "darwin"]
and bindaryTargets = ["native"]
still not workingSlackbot
10/15/2022, 6:56 PMMorten Barklund
10/15/2022, 7:07 PMut dev
10/15/2022, 7:30 PMut dev
10/15/2022, 7:30 PMut dev
10/15/2022, 7:30 PMnilsso
10/15/2022, 8:27 PMprisma migrate
for migrating data from one "old" database to the schema.prisma
datasource "new" database? I'd love to do something likeINSERT INTO `new`.`Foo`
SELECT `bar`
FROM `old`.`Foo`;
Okay it seems it really was that easy, nevermind!