File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,13 @@ export type PullOptions = {
2020 out ?: string ;
2121 naming ?: 'pascal' | 'camel' | 'snake' | 'kebab' | 'none' ;
2222 alwaysMap ?: boolean ;
23+ excludeSchemas : string [ ] ;
2324} ;
2425
2526/**
2627 * CLI action for db related commands
2728 */
28- export async function run ( command : string , options : PushOptions ) {
29+ export async function run ( command : string , options : any ) {
2930 switch ( command ) {
3031 case 'push' :
3132 await runPush ( options ) ;
@@ -89,7 +90,9 @@ async function runPull(options: PullOptions) {
8990 throw new Error ( `No introspection provider found for: ${ datasource . provider } ` ) ;
9091 }
9192
92- const { enums, tables } = await provider . introspect ( datasource . url ) ;
93+ const { enums : allEnums , tables : allTables } = await provider . introspect ( datasource . url ) ;
94+ const enums = allEnums . filter ( ( e ) => ! options . excludeSchemas . includes ( e . schema_name ) ) ;
95+ const tables = allTables . filter ( ( t ) => ! options . excludeSchemas . includes ( t . schema ) ) ;
9396
9497 const newModel : Model = {
9598 $type : 'Model' ,
Original file line number Diff line number Diff line change @@ -41,6 +41,15 @@ export function syncEnums({
4141 return builder ;
4242 } ) ;
4343 } ) ;
44+
45+ if ( dbEnum . schema_name && dbEnum . schema_name != '' && dbEnum . schema_name !== 'public' ) {
46+ factory . addAttribute ( ( b ) =>
47+ b
48+ . setDecl ( getAttributeRef ( '@@schema' , services ) )
49+ . addArg ( ( a ) => a . StringLiteral . setValue ( dbEnum . schema_name ) ) ,
50+ ) ;
51+ }
52+
4453 model . declarations . push ( factory . get ( { $container : model } ) ) ;
4554 }
4655}
@@ -316,6 +325,12 @@ export function syncTable({
316325 ) ;
317326 } ) ;
318327
328+ if ( table . schema && table . schema != '' && table . schema !== 'public' ) {
329+ modelFactory . addAttribute ( ( b ) =>
330+ b . setDecl ( getAttributeRef ( '@@schema' , services ) ) . addArg ( ( a ) => a . StringLiteral . setValue ( table . schema ) ) ,
331+ ) ;
332+ }
333+
319334 model . declarations . push ( modelFactory . node ) ;
320335
321336 return relations ;
Original file line number Diff line number Diff line change @@ -142,7 +142,8 @@ function createProgram() {
142142 . description ( 'Introspect your database.' )
143143 . addOption ( schemaOption )
144144 . addOption ( noVersionCheckOption )
145- . addOption ( new Option ( '--out <path>' , 'add custom output path for the introspected schema' ) )
145+ . addOption ( new Option ( '-e, --exclude-schemas <schemas...>' , 'exclude specific schemas from introspection' ) )
146+ . addOption ( new Option ( '-o, --out <path>' , 'add custom output path for the introspected schema' ) )
146147 . action ( ( options ) => dbAction ( 'pull' , options ) ) ;
147148
148149 dbCommand
You can’t perform that action at this time.
0 commit comments