File tree Expand file tree Collapse file tree 2 files changed +57
-2
lines changed
Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -176,10 +176,23 @@ export class PrismaSchemaGenerator {
176176
177177 private generateDefaultGenerator ( prisma : PrismaModel ) {
178178 const gen = prisma . addGenerator ( 'client' , [ { name : 'provider' , text : '"prisma-client-js"' } ] ) ;
179+
180+ const previewFeatures : string [ ] = [ ] ;
181+
179182 const dataSource = this . zmodel . declarations . find ( isDataSource ) ;
180183 if ( dataSource ?. fields . some ( ( f ) => f . name === 'extensions' ) ) {
181- // enable "postgresqlExtensions" preview feature
182- gen . fields . push ( { name : 'previewFeatures' , text : '["postgresqlExtensions"]' } ) ;
184+ previewFeatures . push ( 'postgresqlExtensions' ) ;
185+ }
186+
187+ if ( this . zmodel . declarations . some ( ( d ) => isDataModel ( d ) && d . isView ) ) {
188+ previewFeatures . push ( 'views' ) ;
189+ }
190+
191+ if ( previewFeatures . length > 0 ) {
192+ gen . fields . push ( {
193+ name : 'previewFeatures' ,
194+ text : JSON . stringify ( previewFeatures ) ,
195+ } ) ;
183196 }
184197 }
185198
Original file line number Diff line number Diff line change 1+ import { PrismaSchemaGenerator } from '@zenstackhq/sdk' ;
2+ import { loadSchema } from '@zenstackhq/testtools' ;
3+ import { describe , expect , it } from 'vitest' ;
4+
5+ // https://github.com/zenstackhq/zenstack/issues/2376
6+ describe ( 'Regression for issue 2376' , ( ) => {
7+ it ( 'should include views preview feature when schema contains views' , async ( ) => {
8+ const model = await loadSchema ( `
9+ datasource db {
10+ provider = 'sqlite'
11+ url = 'file:./test.db'
12+ }
13+
14+ model User {
15+ id Int @id @default(autoincrement())
16+ email String @unique
17+ name String?
18+ posts Post[]
19+ }
20+
21+ model Post {
22+ id Int @id @default(autoincrement())
23+ title String
24+ author User? @relation(fields: [authorId], references: [id])
25+ authorId Int?
26+ }
27+
28+ view UserPostCount {
29+ id Int @unique
30+ name String
31+ postCount Int
32+ }
33+ ` ) ;
34+
35+ const generator = new PrismaSchemaGenerator ( model ) ;
36+ const prismaSchema = await generator . generate ( ) ;
37+
38+ // The generated Prisma schema should include previewFeatures with "views"
39+ expect ( prismaSchema ) . toContain ( 'previewFeatures' ) ;
40+ expect ( prismaSchema ) . toContain ( 'views' ) ;
41+ } ) ;
42+ } ) ;
You can’t perform that action at this time.
0 commit comments