Matt Young
11/11/2021, 6:09 AMLeo Romanovsky
11/11/2021, 9:16 AMLessor Known PostgreSQL Features
https://hakibenita.com/postgresql-unknown-features#prevent-setting-the-value-of-an-auto-generated-key it was a top post on hacker news: https://news.ycombinator.com/item?id=29163319
One of the solid pieces of advice it has was to use an alternative primary key column type:
CREATE TABLE sale (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
sold_at TIMESTAMPTZ,
amount INT
);
This blocks users from being able to write directly to the id
field of a schema like above with an error:
db=# INSERT INTO sale (id, sold_at, amount) VALUES (2, now(), 1000);
ERROR: cannot insert into column "id"
DETAIL: Column "id" is an identity column defined as GENERATED ALWAYS.
The
@db.Int @default(autoincrement())
Generates the SERIAL
column in postgres - is it possible to specify a custom column type?
model User {
id String @id 'INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY'
test String?
}
Petr Homoky
11/11/2021, 10:10 AMCant resolve
errors… https://homoky-files.fra1.digitaloceanspaces.com/2021/Screen-Shot-2021-11-11-11-09-32.32.png▾
getStaticProps
. Previously I had version 10.0.4 of Next and it worked. I use monorepo and Prisma is separate lib.Oleg Yarin
11/11/2021, 11:19 AMcreateMany
?Erik Vitger Beuschau
11/11/2021, 12:58 PM@prisma/client
and generate it using npx prisma generate
to see if I could avoid adding @prisma
but didn’t see any change.Paul
11/11/2021, 2:11 PMUncaught (in promise) Error:
Invalid `prisma.groupChatChannelGroup.findMany()` invocation:
Value out of range for the type. The column `lastRead` contained an invalid datetime value with either day or month set to zero.
But the column doesn't exist in the table.
I check out index.d.ts and I find this:
export type GroupChatChannelGroupByOutputType = {
id: Buffer
...
lastRead: Date
...
_count: GroupChatChannelCountAggregateOutputType | null
_avg: GroupChatChannelAvgAggregateOutputType | null
_sum: GroupChatChannelSumAggregateOutputType | null
_min: GroupChatChannelMinAggregateOutputType | null
_max: GroupChatChannelMaxAggregateOutputType | null
}
lastRead: Date shouldn't exist.
How can I debug where this gets made? Thanksuser
11/11/2021, 3:10 PMezeikel
11/11/2021, 3:32 PMconnect
? This doesn't seem to work:
location: {
connect: existingLocation
? {
id: existingLocation?.id,
}
: {},
create: location,
},
Carlos Moreira
11/11/2021, 6:15 PMRoger
11/11/2021, 6:25 PMTron Vo
11/11/2021, 9:20 PMChris Tsongas
11/12/2021, 12:29 AMMoh
11/12/2021, 1:10 AMenum paddock_slope_enum {
One__0____7__ @map("One (0° - 7°)")
Two__8____15__ @map("Two (8° - 15°)")
Three__16____25__ @map("Three (16° - 25°)")
Four___26__ @map("Four (>26°)")
}
The generated enum becomes:
export const paddock_slope_enum: {
One__0____7__: 'One__0____7__',
Two__8____15__: 'Two__8____15__',
Three__16____25__: 'Three__16____25__,
Steep_Hill___26__: 'Steep_Hill___26__'
};
This is unexpected for me as I would have expected the values of the enum keys to be the map values in the schema?
So my findMany GET API is returning the values with all the underscores - why is that? And can I get around it to get the value of the map?Chris Tsongas
11/12/2021, 6:47 AMprisma.$transaction([
prisma.user.update({
where: { id: input.userId },
data: {
tags: {
disconnect: [{ id }],
},
},
}),
prisma.$executeRaw`DELETE FROM "Tag" WHERE id NOT IN (SELECT "B" FROM "_UserToTag")`,
])
Siemen Blok
11/12/2021, 10:11 AMSiemen Blok
11/12/2021, 12:00 PMimport { PrismaClient } from '.prisma/client';
import { mockDeep } from 'jest-mock-extended';
import { DeepMockProxy } from 'jest-mock-extended/lib/cjs/Mock';
export type Context = {
prisma: PrismaClient;
};
export type MockContext = {
prisma: DeepMockProxy<PrismaClient>;
};
export const createMockContext = (): MockContext => {
return {
prisma: mockDeep<PrismaClient>(),
};
};
I'm getting the following error:
Type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; } & PrismaClient<...>' is not assignable to type 'DeepMockProxy<PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>>'.
Type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; } & PrismaClient<...>' is not assignable to type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; }'.
The types of '$on.calledWith' are incompatible between these types.
Type '(...args: [eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules...' is not assignable to type '(...args: [eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/cjs/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_mod...'.
Types of parameters 'args' and 'args' are incompatible.
Type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/cjs/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules/jest-...' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules/jest-mock...'.
Type '[eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<void>) => void>]' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<...>) => void>]'.
Type '[eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<void>) => void>]' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type '"beforeExit" | Matcher<"beforeExit">' is not assignable to type '"beforeExit"'.
Type 'Matcher<"beforeExit">' is not assignable to type '"beforeExit"'.
15 prisma: mockDeep<PrismaClient>(),
~~~~~~
context.ts:10:3
10 prisma: DeepMockProxy<PrismaClient>;
~~~~~~
The expected type comes from property 'prisma' which is declared here on type 'MockContext'
Does anyone know why? Or how I can fix this?Furkan Demirbilek
11/12/2021, 12:27 PMVladi Stevanovic
Oleg Komarov
11/12/2021, 6:13 PMSELECT * FROM table
WHERE (letter, number) IN (('T', 7), ('R', 2))
where table is:
number | letter
7 | 'T'
2 | 'R'
4 | 'T'
if not, joined workaround?Moaaz
11/12/2021, 8:25 PMVersion
model for each model.
E.g.
model User {
id: Int
name: String
}
generated model:
model UserVersion {
id: Int
data: Json
userId Int
user User @relation(fields: [userId], references: [id])
}
Wade McDaniel
11/12/2021, 11:06 PMmodel User {
id String @id @default(cuid()) @db.Char(30)
email String @db.MediumText
admin Admin?
}
model Admin {
id String @id @default(cuid()) @db.Char(30)
name String @db.MediumText
userId String @db.Char(30)
user User @relation(fields: [userId], references: [id], onUpdate: Restrict)
}
And in a Prisma1 GraphQL Playground I run this:
mutation ($data: UserCreateInput!) {
createuser(data: $data) {
id
email
}
}
variables
{
"data" {
"email": "<mailto:diety@supremebeing.org|diety@supremebeing.org>"
"admin": {
"create": {
"name": "me"
}
}
}
}
And I get an error about (conn=3216) Field 'userId' doesn't have a default value
I also checked in MySQL and the foreign key constraint in Admin
for userId
references id
in User
Why isn't Prisma1 inserting userId
into Admin
when I create a user with a nested create for Admin
? Is that something that Prisma1 can't do?Awey
11/13/2021, 8:35 AMmodel User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
username String @db.VarChar(50)
password String
...
}
model Message {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
subject String
body String
}
I'm having trouble understanding how to best setup the relationships for a 1 on 1 private messaging system.
I'd like for it to work similar to how Reddit handles private messages. Could someone point me in the right direction please.Phil Bookst
11/13/2021, 9:43 AMnum_physical_cpus * 2 + 1
but using planetscale we can use up to 10k concurrent requestspeter
11/13/2021, 10:49 AMBjørn Atle Isaksen
11/13/2021, 12:18 PMprisma.$use(async (params, next) => {
if (params.model == 'Post' && params.action == 'create') {
params.args.data.language = contextLanguage
}
return next(params)
})
Kristofer Pervin
11/13/2021, 4:56 PMMoaaz
11/14/2021, 3:03 AM@@index
Writing a plugin that does versioning to store history of changes on a data model – for each Datamodel
, would like to define a DatamodelVersion
model which specifies some fields for storing history and some references to Datamodel
In addition would like to add versions: DatamodelVersion
to the original Datamodel
schema. But in doing so, losing any @@index
that is defined on the original Datamodel
schema.Akshay Kadam (A2K)
11/14/2021, 10:52 AMmodel Settings {
id String @id @default(cuid())
timezone String @default("UTC")
user User[]
}
It threw migration error so I used --create-only
but don't know how to fix it. I've been redirected to https://pris.ly/d/migrate-resolve but don't see anything there that helps me.
The error is:
Applying migration `20211114104346_create_settings`
Error: P3018
A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
Migration name: 20211114104346_create_settings
Database error code: 23502
Database error:
ERROR: column "settingsId" of relation "User" contains null values
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("23502"), message: "column \"settingsId\" of relation \"User\" contains null values", detail: None, hint: None, position: None, where_: None, schema: Some("public"), table: Some("User"), column: Some("settingsId"), datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(5815), routine: Some("ATRewriteTable") }
How do I fix it?ldlework
11/14/2021, 2:29 PMPeter Kellner
11/14/2021, 3:00 PMInvalid `prisma.noteOnTag.delete()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timed out during query execution.) })
This is for a Pluralsight course I'm working on, and though the source is not public yet, I can share it if that helps.