1- import { Model , Enum , DataModel , DataField } from '@zenstackhq/language/ast' ;
2- import { ZModelCodeGenerator } from '@zenstackhq/sdk' ;
1+ import { config } from '@dotenvx/dotenvx' ;
2+ import { ZModelCodeGenerator } from '@zenstackhq/language' ;
3+ import { type DataField , DataModel , Enum , type Model } from '@zenstackhq/language/ast' ;
34import fs from 'node:fs' ;
45import path from 'node:path' ;
56import { execPrisma } from '../utils/exec-utils' ;
67import { generateTempPrismaSchema , getSchemaFile , handleSubProcessError , requireDataSourceUrl , loadSchemaDocumentWithServices } from './action-utils' ;
78import { syncEnums , syncRelation , syncTable , type Relation } from './pull' ;
89import { providers } from './pull/provider' ;
910import { getDatasource , getDbName , getRelationFkName } from './pull/utils' ;
10- import { config } from '@dotenvx/dotenvx' ;
1111
1212type PushOptions = {
1313 schema ?: string ;
@@ -17,7 +17,6 @@ type PushOptions = {
1717
1818export type PullOptions = {
1919 schema ?: string ;
20- excludeSchemas ?: string [ ] ;
2120 out ?: string ;
2221 modelCasing : 'pascal' | 'camel' | 'snake' | 'kebab' | 'none' ;
2322 fieldCasing : 'pascal' | 'camel' | 'snake' | 'kebab' | 'none' ;
@@ -74,7 +73,7 @@ async function runPush(options: PushOptions) {
7473async function runPull ( options : PullOptions ) {
7574 try {
7675 const schemaFile = getSchemaFile ( options . schema ) ;
77- const { model, services } = await loadSchemaDocumentWithServices ( schemaFile ) ;
76+ const { model, services } = await loadSchemaDocument ( schemaFile , { returnServices : true } ) ;
7877 config ( ) ;
7978 const SUPPORTED_PROVIDERS = [ 'sqlite' , 'postgresql' ] ;
8079 const datasource = getDatasource ( model ) ;
@@ -94,8 +93,8 @@ async function runPull(options: PullOptions) {
9493 }
9594
9695 const { enums : allEnums , tables : allTables } = await provider . introspect ( datasource . url ) ;
97- const enums = allEnums . filter ( ( e ) => ! options . excludeSchemas ? .includes ( e . schema_name ) ) ;
98- const tables = allTables . filter ( ( t ) => ! options . excludeSchemas ? .includes ( t . schema ) ) ;
96+ const enums = allEnums . filter ( ( e ) => datasource . schemas . includes ( e . schema_name ) ) ;
97+ const tables = allTables . filter ( ( t ) => datasource . schemas . includes ( t . schema ) ) ;
9998
10099 const newModel : Model = {
101100 $type : 'Model' ,
@@ -106,11 +105,18 @@ async function runPull(options: PullOptions) {
106105 imports : [ ] ,
107106 } ;
108107
109- syncEnums ( { dbEnums : enums , model : newModel , services, options } ) ;
108+ syncEnums ( { dbEnums : enums , model : newModel , services, options, defaultSchema : datasource . defaultSchema } ) ;
110109
111110 const resolvedRelations : Relation [ ] = [ ] ;
112111 for ( const table of tables ) {
113- const relations = syncTable ( { table, model : newModel , provider, services, options } ) ;
112+ const relations = syncTable ( {
113+ table,
114+ model : newModel ,
115+ provider,
116+ services,
117+ options,
118+ defaultSchema : datasource . defaultSchema ,
119+ } ) ;
114120 resolvedRelations . push ( ...relations ) ;
115121 }
116122
0 commit comments