-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(delegate): don't generate both "@@Schema" attributes from base an…
…d sub models
- Loading branch information
Showing
2 changed files
with
85 additions
and
1 deletion.
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,69 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
import fs from 'fs'; | ||
|
||
describe('issue 1647', () => { | ||
it('inherits @@schema by default', async () => { | ||
const { projectDir } = await loadSchema( | ||
` | ||
datasource db { | ||
provider = 'postgresql' | ||
url = env('DATABASE_URL') | ||
schemas = ['public', 'post'] | ||
} | ||
generator client { | ||
provider = 'prisma-client-js' | ||
previewFeatures = ['multiSchema'] | ||
} | ||
model Asset { | ||
id Int @id | ||
type String | ||
@@delegate(type) | ||
@@schema('public') | ||
} | ||
model Post extends Asset { | ||
title String | ||
} | ||
`, | ||
{ addPrelude: false, pushDb: false, getPrismaOnly: true } | ||
); | ||
|
||
const prismaSchema = fs.readFileSync(`${projectDir}/prisma/schema.prisma`, 'utf-8'); | ||
expect(prismaSchema.split('\n').filter((l) => l.includes('@@schema("public")'))).toHaveLength(2); | ||
}); | ||
it('respects sub model @@schema overrides', async () => { | ||
const { projectDir } = await loadSchema( | ||
` | ||
datasource db { | ||
provider = 'postgresql' | ||
url = env('DATABASE_URL') | ||
schemas = ['public', 'post'] | ||
} | ||
generator client { | ||
provider = 'prisma-client-js' | ||
previewFeatures = ['multiSchema'] | ||
} | ||
model Asset { | ||
id Int @id | ||
type String | ||
@@delegate(type) | ||
@@schema('public') | ||
} | ||
model Post extends Asset { | ||
title String | ||
@@schema('post') | ||
} | ||
`, | ||
{ addPrelude: false, pushDb: false, getPrismaOnly: true } | ||
); | ||
|
||
const prismaSchema = fs.readFileSync(`${projectDir}/prisma/schema.prisma`, 'utf-8'); | ||
expect(prismaSchema.split('\n').filter((l) => l.includes('@@schema("public")'))).toHaveLength(1); | ||
expect(prismaSchema.split('\n').filter((l) => l.includes('@@schema("post")'))).toHaveLength(1); | ||
}); | ||
}); |