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 @@ -25,12 +25,13 @@ export type PullOptions = {
2525 out ?: string ;
2626 naming ?: 'pascal' | 'camel' | 'snake' | 'kebab' | 'none' ;
2727 alwaysMap ?: boolean ;
28+ excludeSchemas : string [ ] ;
2829} ;
2930
3031/**
3132 * CLI action for db related commands
3233 */
33- export async function run ( command : string , options : PushOptions ) {
34+ export async function run ( command : string , options : any ) {
3435 switch ( command ) {
3536 case 'push' :
3637 await runPush ( options ) ;
@@ -90,7 +91,9 @@ async function runPull(options: PullOptions) {
9091 throw new Error ( `No introspection provider found for: ${ datasource . provider } ` ) ;
9192 }
9293
93- const { enums, tables } = await provider . introspect ( datasource . url ) ;
94+ const { enums : allEnums , tables : allTables } = await provider . introspect ( datasource . url ) ;
95+ const enums = allEnums . filter ( ( e ) => ! options . excludeSchemas . includes ( e . schema_name ) ) ;
96+ const tables = allTables . filter ( ( t ) => ! options . excludeSchemas . includes ( t . schema ) ) ;
9497
9598 const newModel : Model = {
9699 $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 @@ -126,7 +126,8 @@ function createProgram() {
126126 . description ( 'Introspect your database.' )
127127 . addOption ( schemaOption )
128128 . addOption ( noVersionCheckOption )
129- . addOption ( new Option ( '--out <path>' , 'add custom output path for the introspected schema' ) )
129+ . addOption ( new Option ( '-e, --exclude-schemas <schemas...>' , 'exclude specific schemas from introspection' ) )
130+ . addOption ( new Option ( '-o, --out <path>' , 'add custom output path for the introspected schema' ) )
130131 . action ( ( options ) => dbAction ( 'pull' , options ) ) ;
131132
132133 program
You can’t perform that action at this time.
0 commit comments