Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ensure the emulated referential action NoAction is invalid for postgres and sqlite #15880

Merged
merged 9 commits into from
Oct 21, 2022
48 changes: 48 additions & 0 deletions packages/migrate/src/__tests__/DbPush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,54 @@ const describeIf = (condition: boolean) => (condition ? describe : describe.skip
const ctx = jestContext.new().add(jestConsoleContext()).assemble()

describeIf(process.platform !== 'win32')('push', () => {
it('fails with relationMode = "prisma" + NoAction referential action on Postgres', async () => {
ctx.fixture('referential-actions/no-action/relationMode-prisma')

const result = DbPush.new().parse(['--schema', './prisma/postgres.prisma'])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
P1012

error: Error validating: Invalid referential action: \`NoAction\`. Allowed values: (\`Cascade\`, \`Restrict\`, \`SetNull\`). \`NoAction\` is not implemented for Postgres when using \`relationMode = "prisma"\`, you could try using \`Restrict\` instead. Learn more at https://pris.ly/d/relationMode
--> schema.prisma:21
|
20 | id String @id @default(cuid())
21 | user SomeUser @relation(fields: [userId], references: [id], onUpdate: NoAction)
|
error: Error validating: Invalid referential action: \`NoAction\`. Allowed values: (\`Cascade\`, \`Restrict\`, \`SetNull\`). \`NoAction\` is not implemented for Postgres when using \`relationMode = "prisma"\`, you could try using \`Restrict\` instead. Learn more at https://pris.ly/d/relationMode
--> schema.prisma:28
|
27 | id String @id @default(cuid())
28 | user SomeUser @relation(fields: [userId], references: [id], onDelete: NoAction)
|


`)
})

it('fails with relationMode = "prisma" + NoAction referential action on sqlite', async () => {
ctx.fixture('referential-actions/no-action/relationMode-prisma')

const result = DbPush.new().parse(['--schema', './prisma/sqlite.prisma'])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
P1012

error: Error validating: Invalid referential action: \`NoAction\`. Allowed values: (\`Cascade\`, \`Restrict\`, \`SetNull\`). \`NoAction\` is not implemented for sqlite when using \`relationMode = "prisma"\`, you could try using \`Restrict\` instead. Learn more at https://pris.ly/d/relationMode
--> schema.prisma:20
|
19 | id String @id @default(cuid())
20 | user SomeUser @relation(fields: [userId], references: [id], onUpdate: NoAction, onDelete: NoAction)
|
error: Error validating: Invalid referential action: \`NoAction\`. Allowed values: (\`Cascade\`, \`Restrict\`, \`SetNull\`). \`NoAction\` is not implemented for sqlite when using \`relationMode = "prisma"\`, you could try using \`Restrict\` instead. Learn more at https://pris.ly/d/relationMode
--> schema.prisma:20
|
19 | id String @id @default(cuid())
20 | user SomeUser @relation(fields: [userId], references: [id], onUpdate: NoAction, onDelete: NoAction)
|


`)
})

it('--preview-feature flag is not required anymore', async () => {
ctx.fixture('empty')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}

datasource db {
provider = "postgres"
url = env("TEST_POSTGRES_URI")
relationMode = "prisma"
}

model SomeUser {
id String @id @default(cuid())
profileUpdate ProfileUpdateNoAction?
profileDelete ProfileDeleteNoAction?
enabled Boolean?
}

model ProfileUpdateNoAction {
id String @id @default(cuid())
user SomeUser @relation(fields: [userId], references: [id], onUpdate: NoAction)
userId String @unique
enabled Boolean?
}

model ProfileDeleteNoAction {
id String @id @default(cuid())
user SomeUser @relation(fields: [userId], references: [id], onDelete: NoAction)
userId String @unique
enabled Boolean?
}
jkomyno marked this conversation as resolved.
Show resolved Hide resolved

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}

datasource db {
provider = "sqlite"
url = "file:./db.dev"
relationMode = "prisma"
}

model SomeUser {
id String @id @default(cuid())
profileNoAction ProfileNoAction?
enabled Boolean?
}

model ProfileNoAction {
id String @id @default(cuid())
user SomeUser @relation(fields: [userId], references: [id], onUpdate: NoAction, onDelete: NoAction)
userId String @unique
enabled Boolean?
}