|
| 1 | +import { loadSchema } from '@zenstackhq/testtools'; |
| 2 | +import fs from 'fs'; |
| 3 | + |
| 4 | +describe('issue 1647', () => { |
| 5 | + it('inherits @@schema by default', async () => { |
| 6 | + const { projectDir } = await loadSchema( |
| 7 | + ` |
| 8 | + datasource db { |
| 9 | + provider = 'postgresql' |
| 10 | + url = env('DATABASE_URL') |
| 11 | + schemas = ['public', 'post'] |
| 12 | + } |
| 13 | +
|
| 14 | + generator client { |
| 15 | + provider = 'prisma-client-js' |
| 16 | + previewFeatures = ['multiSchema'] |
| 17 | + } |
| 18 | +
|
| 19 | + model Asset { |
| 20 | + id Int @id |
| 21 | + type String |
| 22 | + @@delegate(type) |
| 23 | + @@schema('public') |
| 24 | + } |
| 25 | + |
| 26 | + model Post extends Asset { |
| 27 | + title String |
| 28 | + } |
| 29 | + `, |
| 30 | + { addPrelude: false, pushDb: false, getPrismaOnly: true } |
| 31 | + ); |
| 32 | + |
| 33 | + const prismaSchema = fs.readFileSync(`${projectDir}/prisma/schema.prisma`, 'utf-8'); |
| 34 | + expect(prismaSchema.split('\n').filter((l) => l.includes('@@schema("public")'))).toHaveLength(2); |
| 35 | + }); |
| 36 | + it('respects sub model @@schema overrides', async () => { |
| 37 | + const { projectDir } = await loadSchema( |
| 38 | + ` |
| 39 | + datasource db { |
| 40 | + provider = 'postgresql' |
| 41 | + url = env('DATABASE_URL') |
| 42 | + schemas = ['public', 'post'] |
| 43 | + } |
| 44 | +
|
| 45 | + generator client { |
| 46 | + provider = 'prisma-client-js' |
| 47 | + previewFeatures = ['multiSchema'] |
| 48 | + } |
| 49 | +
|
| 50 | + model Asset { |
| 51 | + id Int @id |
| 52 | + type String |
| 53 | + @@delegate(type) |
| 54 | + @@schema('public') |
| 55 | + } |
| 56 | + |
| 57 | + model Post extends Asset { |
| 58 | + title String |
| 59 | + @@schema('post') |
| 60 | + } |
| 61 | + `, |
| 62 | + { addPrelude: false, pushDb: false, getPrismaOnly: true } |
| 63 | + ); |
| 64 | + |
| 65 | + const prismaSchema = fs.readFileSync(`${projectDir}/prisma/schema.prisma`, 'utf-8'); |
| 66 | + expect(prismaSchema.split('\n').filter((l) => l.includes('@@schema("public")'))).toHaveLength(1); |
| 67 | + expect(prismaSchema.split('\n').filter((l) => l.includes('@@schema("post")'))).toHaveLength(1); |
| 68 | + }); |
| 69 | +}); |
0 commit comments