@vbilopav/pgmigrations
Advanced tools
Comparing version 0.22.0 to 0.23.0
@@ -379,2 +379,3 @@ const path = require("path"); | ||
process.exit(config.failureExitCode); | ||
return; | ||
} | ||
@@ -409,2 +410,3 @@ upVersions[version] = script; | ||
process.exit(config.failureExitCode); | ||
return; | ||
} | ||
@@ -763,2 +765,3 @@ downVersions[version] = script; | ||
process.exit(config.failureExitCode); | ||
return; | ||
} else { | ||
@@ -774,2 +777,3 @@ console.info("Migration completed successfully."); | ||
process.exit(config.failureExitCode); | ||
return; | ||
} | ||
@@ -787,2 +791,3 @@ | ||
process.exit(config.failureExitCode); | ||
return; | ||
} | ||
@@ -789,0 +794,0 @@ } |
{ | ||
"name": "@vbilopav/pgmigrations", | ||
"version": "0.22.0", | ||
"version": "0.23.0", | ||
"description": "PostgreSQL Migration Tool for Node.js and NPM", | ||
@@ -5,0 +5,0 @@ "author": "vb-consulting", |
@@ -82,3 +82,3 @@ #!/usr/bin/env node | ||
{key: "history", value: "console.log the current migration schema history."}, | ||
{key: "run | exec", value: "Run a command or a script file with psql. Command text or a script file is required as the second argument. Any additional arguments will be passed to a psql command."}, | ||
{key: "run | exec", value: "Run a command or a script file or script directory with psql. Command text or a script file is required as the second argument. Any additional arguments will be passed to a psql command."}, | ||
{key: "dump | schema", value: "Run pg_dump command with --schema-only --encoding=UTF8 swtiches on (plus schemaDumpAdditionalArgs from the config). Any additional arguments will be passed to pg_dump command."}, | ||
@@ -85,0 +85,0 @@ {key: "psql", value: "Run arbitrary psql command or open psql shell. Any additional arguments will be passed to a psql."}, |
@@ -26,3 +26,3 @@ # PgMigrations | ||
history console.log the current migration schema history. | ||
run | exec Run a command or a script file with psql. Command text or a script file is required as the second argument. Any additional arguments will be passed to a psql command. | ||
run | exec Run a command or a script file or script directory with psql. Command text or a script file is required as the second argument. Any additional arguments will be passed to a psql command. | ||
dump | schema Run pg_dump command with --schema-only --encoding=UTF8 swtiches on (plus schemaDumpAdditionalArgs from the config). Any additional arguments will be passed to pg_dump command. | ||
@@ -60,2 +60,8 @@ psql Run arbitrary psql command or open psql shell. Any additional arguments will be passed to a psql. | ||
- Execute a list of sql files in a dir: | ||
```console | ||
> npx pgmigrations run ./dir | ||
``` | ||
- List all tables | ||
@@ -62,0 +68,0 @@ |
const fs = require("fs"); | ||
const cp = require("child_process"); | ||
const {info, error, warning} = require("./log.js"); | ||
const path = require("path"); | ||
@@ -183,3 +184,31 @@ function run(options) { | ||
var fileExists = false; | ||
var isDir = false; | ||
if (!isCommand) { | ||
isDir = (fs.existsSync(command) && fs.lstatSync(command).isDirectory()); | ||
if (isDir) { | ||
var files = fs.readdirSync(command, {recursive: true}); | ||
for (let i = 0; i < files.length; i++) { | ||
let file = files[i]; | ||
if (file.endsWith(".sql")) { | ||
file = path.join(command, file); | ||
info(file); | ||
run({ | ||
command: config.psql, | ||
config: config, | ||
sql: undefined, | ||
file: file, | ||
dump: false, | ||
additionalArgs: additionalArgs, | ||
verbose: opt.verbose, | ||
inherit: false, | ||
returnBuffer: false, | ||
muted: muted | ||
}); | ||
} | ||
} | ||
return; | ||
} | ||
} | ||
if (!isCommand) { | ||
fileExists = (fs.existsSync(command) && fs.lstatSync(command).isFile()); | ||
@@ -186,0 +215,0 @@ } |
82460
1466
519