@@ -21,7 +21,6 @@ import { ddlDiff } from '../../dialects/postgres/diff';
2121import { fromDrizzleSchema , prepareFromSchemaFiles } from '../../dialects/postgres/drizzle' ;
2222import type { JsonStatement } from '../../dialects/postgres/statements' ;
2323import type { DB } from '../../utils' ;
24- import { mockResolver } from '../../utils/mocks' ;
2524import { prepareFilenames } from '../../utils/utils-node' ;
2625import { resolver } from '../prompts' ;
2726import { Select } from '../selector-ui' ;
@@ -37,18 +36,36 @@ export const handle = async (
3736 strict : boolean ,
3837 credentials : PostgresCredentials ,
3938 tablesFilter : string [ ] ,
40- schemasFilter : string [ ] ,
39+ allowedSchemas : string [ ] ,
4140 entities : Entities ,
4241 force : boolean ,
4342 casing : CasingType | undefined ,
4443) => {
4544 const { preparePostgresDB } = await import ( '../connections' ) ;
46- const { introspect : pgPushIntrospect } = await import ( './pull-postgres' ) ;
45+ const { introspect } = await import ( './pull-postgres' ) ;
4746
4847 const db = await preparePostgresDB ( credentials ) ;
4948 const filenames = prepareFilenames ( schemaPath ) ;
5049 const res = await prepareFromSchemaFiles ( filenames ) ;
5150
51+ console . log ( allowedSchemas ) ;
52+ if ( allowedSchemas . length > 0 ) {
53+ const toCheck = res . schemas . map ( ( it ) => it . schemaName ) . filter ( ( it ) => it !== 'public' ) ;
54+ const missing = toCheck . filter ( ( it ) => ! allowedSchemas . includes ( it ) ) ;
55+ if ( missing . length > 0 ) {
56+ const missingArr = missing . map ( ( it ) => chalk . underline ( it ) ) . join ( ', ' ) ;
57+ const allowedArr = allowedSchemas . map ( ( it ) => chalk . underline ( it ) ) . join ( ', ' ) ;
58+ render (
59+ `[${ chalk . red ( 'x' ) } ] ${ missingArr } schemas missing in drizzle config file "schemaFilter": [${ allowedArr } ]` ,
60+ ) ;
61+ // TODO: write a guide and link here
62+ process . exit ( 1 ) ;
63+ }
64+ } else {
65+ allowedSchemas . push ( ...res . schemas . map ( ( it ) => it . schemaName ) ) ;
66+ }
67+ console . log ( '.' , allowedSchemas ) ;
68+
5269 const { schema : schemaTo , errors, warnings } = fromDrizzleSchema ( res , casing ) ;
5370
5471 if ( warnings . length > 0 ) {
@@ -61,11 +78,11 @@ export const handle = async (
6178 }
6279
6380 const progress = new ProgressView ( 'Pulling schema from database...' , 'Pulling schema from database...' ) ;
64- const { schema : schemaFrom } = await pgPushIntrospect ( db , tablesFilter , schemasFilter , entities , progress ) ;
81+ const { schema : schemaFrom } = await introspect ( db , tablesFilter , allowedSchemas , entities , progress ) ;
6582
6683 const { ddl : ddl1 , errors : errors1 } = interimToDDL ( schemaFrom ) ;
6784 const { ddl : ddl2 , errors : errors2 } = interimToDDL ( schemaTo ) ;
68- // todo : handle errors?
85+ // TODO : handle errors?
6986
7087 if ( errors1 . length > 0 ) {
7188 console . log ( errors . map ( ( it ) => postgresSchemaError ( it ) ) . join ( '\n' ) ) ;
0 commit comments