|
| 1 | +import { PrismaSchemaGenerator } from '@zenstackhq/sdk'; |
| 2 | +import { loadSchema } from '@zenstackhq/testtools'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | + |
| 5 | +describe('PrismaSchemaGenerator partial index', () => { |
| 6 | + it('should pass @@index where string argument through to Prisma schema', async () => { |
| 7 | + const model = await loadSchema(` |
| 8 | +datasource db { |
| 9 | + provider = 'postgresql' |
| 10 | + url = 'env("DATABASE_URL")' |
| 11 | +} |
| 12 | +
|
| 13 | +model Foo { |
| 14 | + id Int @id |
| 15 | + @@index([id], where: "id > 0") |
| 16 | +} |
| 17 | + `); |
| 18 | + |
| 19 | + const generator = new PrismaSchemaGenerator(model); |
| 20 | + const schema = await generator.generate(); |
| 21 | + expect(schema).toContain('@@index([id], where: "id > 0")'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should pass @@index where object argument through to Prisma schema', async () => { |
| 25 | + const model = await loadSchema(` |
| 26 | +datasource db { |
| 27 | + provider = 'postgresql' |
| 28 | + url = 'env("DATABASE_URL")' |
| 29 | +} |
| 30 | +
|
| 31 | +model Foo { |
| 32 | + id Int @id |
| 33 | + published Boolean |
| 34 | + @@index([id], where: { published: true }) |
| 35 | +} |
| 36 | + `); |
| 37 | + |
| 38 | + const generator = new PrismaSchemaGenerator(model); |
| 39 | + const schema = await generator.generate(); |
| 40 | + expect(schema).toContain('@@index([id], where: { published: true })'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should pass @@unique where argument through to Prisma schema', async () => { |
| 44 | + const model = await loadSchema(` |
| 45 | +datasource db { |
| 46 | + provider = 'postgresql' |
| 47 | + url = 'env("DATABASE_URL")' |
| 48 | +} |
| 49 | +
|
| 50 | +model Foo { |
| 51 | + id Int @id |
| 52 | + email String |
| 53 | + @@unique([email], where: "email IS NOT NULL") |
| 54 | +} |
| 55 | + `); |
| 56 | + |
| 57 | + const generator = new PrismaSchemaGenerator(model); |
| 58 | + const schema = await generator.generate(); |
| 59 | + expect(schema).toContain('@@unique([email], where: "email IS NOT NULL")'); |
| 60 | + }); |
| 61 | +}); |
0 commit comments