From 8e05e788aa8aa9006f323d6c529fbd1fa32bf129 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Thu, 27 Jun 2024 16:54:54 +0200 Subject: [PATCH] fix(cli): correctly validate schema (#1216) --- bin/node-pg-migrate.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/node-pg-migrate.ts b/bin/node-pg-migrate.ts index 74033223..5983165e 100755 --- a/bin/node-pg-migrate.ts +++ b/bin/node-pg-migrate.ts @@ -239,7 +239,7 @@ let MIGRATIONS_DIR = argv[migrationsDirArg]; let DB_CONNECTION: string | ConnectionParameters | ClientConfig | undefined = process.env[argv[databaseUrlVarArg]]; let IGNORE_PATTERN = argv[ignorePatternArg]; -let SCHEMA = argv[schemaArg]; +let SCHEMA: string | string[] | undefined = argv[schemaArg]; let CREATE_SCHEMA = argv[createSchemaArg]; let MIGRATIONS_SCHEMA = argv[migrationsSchemaArg]; let CREATE_MIGRATIONS_SCHEMA = argv[createMigrationsSchemaArg]; @@ -343,8 +343,12 @@ function isClientConfig(val: unknown): val is ClientConfig & { name?: string } { function readJson(json: unknown): void { if (typeof json === 'object' && json !== null) { - SCHEMA = applyIf(SCHEMA, schemaArg, json, (val): val is string[] => - Array.isArray(val) + SCHEMA = applyIf( + SCHEMA, + schemaArg, + json, + (val): val is string | string[] => + Array.isArray(val) || (isString(val) && val.length > 0) ); CREATE_SCHEMA = applyIf(CREATE_SCHEMA, createSchemaArg, json, isBoolean); MIGRATIONS_DIR = applyIf(MIGRATIONS_DIR, migrationsDirArg, json, isString);