-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure the emulated referential action
NoAction
is invalid fo…
…r postgres and sqlite (#15880) * [skip ci] test: ensure NoAction is invalid for Postgres and sqlite when relationMode = "prisma" * chore: trigger CI * test: add Validate.test.ts, moved referential-actions tests from DbPush.test.ts to Validate.test.ts * chore: add successful NoAction test in Validate.test.ts * chore: add missing folder * chore: fix ci? add env to cli-commands * chore: add normalization to Validate.test.ts
- Loading branch information
Showing
5 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { jestContext, serializeQueryEngineName } from '@prisma/internals' | ||
|
||
import { Validate } from '../../Validate' | ||
|
||
const ctx = jestContext.new().assemble() | ||
|
||
it('validate should throw if schema is broken', async () => { | ||
ctx.fixture('example-project/prisma') | ||
await expect(Validate.new().parse(['--schema=broken.prisma'])).rejects.toThrowError() | ||
}) | ||
|
||
describe('referential actions', () => { | ||
beforeEach(() => { | ||
ctx.fixture('referential-actions/no-action/relationMode-prisma') | ||
}) | ||
|
||
it('validate should reject NoAction referential action on Postgres when relationMode = "prisma"', async () => { | ||
expect.assertions(1) | ||
|
||
try { | ||
await Validate.new().parse(['--schema', './prisma/postgres.prisma']) | ||
} catch (e) { | ||
expect(serializeQueryEngineName(e.message)).toMatchInlineSnapshot(` | ||
Schema validation error - Error (query-engine-NORMALIZED) | ||
Error code: 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) | ||
| | ||
Validation Error Count: 2 | ||
[Context: getDmmf] | ||
Prisma CLI Version : 0.0.0 | ||
`) | ||
} | ||
}) | ||
|
||
it('validate should reject NoAction referential action on sqlite when relationMode = "prisma"', async () => { | ||
expect.assertions(1) | ||
|
||
try { | ||
await Validate.new().parse(['--schema', './prisma/postgres.prisma']) | ||
} catch (e) { | ||
expect(serializeQueryEngineName(e.message)).toMatchInlineSnapshot(` | ||
Schema validation error - Error (query-engine-NORMALIZED) | ||
Error code: 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) | ||
| | ||
Validation Error Count: 2 | ||
[Context: getDmmf] | ||
Prisma CLI Version : 0.0.0 | ||
`) | ||
} | ||
}) | ||
|
||
it('validate should accept NoAction referential action on e.g. MySQL when relationMode = "prisma"', async () => { | ||
const result = await Validate.new().parse(['--schema', './prisma/mysql.prisma']) | ||
expect(result).toBeTruthy() | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
.../__tests__/fixtures/referential-actions/no-action/relationMode-prisma/prisma/mysql.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "mysql" | ||
url = env("TEST_MYSQL_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? | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
...tests__/fixtures/referential-actions/no-action/relationMode-prisma/prisma/postgres.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
...__tests__/fixtures/referential-actions/no-action/relationMode-prisma/prisma/sqlite.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
} |