michaelsogos / pg-diff

PostgreSQL schema and data comparing tool
MIT License
165 stars 16 forks source link

Feature request: some options and defaults for file handling #37

Closed codemonstur closed 3 years ago

codemonstur commented 3 years ago

Some feature requests:

michaelsogos commented 3 years ago

Dear @codemonstur

I can agree with you that a "-f" option make sense; but actually the "-o" flag is included into config file so not makes sense to me. Of course i can give opportunity to specify absolute path intesad of relative path only. When "outputDirectory" isn't specified i can assume the CWD.

michaelsogos commented 3 years ago

I wanna think it again. The "-o" option has totally sense in order to allow scriptable dynamic solution, where "outputDirectory" is not predictable but instead dynamically passed as CLI argument.

Is it your environment? isn't it? 😄

codemonstur commented 3 years ago

Yep, this is exactly what I'm trying to achieve. I can make the script work with how it is designed now but it would work much better and with fewer quirks with these CLI arguments. :)

michaelsogos commented 3 years ago

Dear @codemonstur

Release 2.2.0, read docs please 😄

Can you test it?

codemonstur commented 3 years ago

I put the config file in src/main/db/pg-diff-config.json. And ran this command: pg-diff -f src/main/db/pg-diff-config.json -c generate migration. This worked great and generated my migration script. Yey!

I did run into a couple of quirks along the way. If I rearrange the arguments I get an error:

$ pg-diff -c generate -f src/main/db/pg-diff-config.json migration
                              _   _    __    __                  _   _
  _ __     __ _            __| | (_)  / _|  / _|           ___  | | (_)
 | '_ \   / _` |  _____   / _` | | | | |_  | |_   _____   / __| | | | |
 | |_) | | (_| | |_____| | (_| | | | |  _| |  _| |_____| | (__  | | | |
 | .__/   \__, |          \__,_| |_| |_|   |_|            \___| |_| |_|
 |_|      |___/

     Author: Michael Sogos <michael.sogos@gurustudioweb.it> (https://github.com/michaelsogos)
    Version: 2.2.0
 PostgreSQL: 9.6+
    License: MIT
Description: PostgreSQL schema and data comparing tool

Error: Missing or invalid arguments for option 'COMPARE'!
    at Run (/usr/local/lib/node_modules/pg-diff-cli/main.js:153:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/pg-diff-cli/main.js:17:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Missing or invalid arguments for option 'COMPARE'!

==============================
===   pg-diff-cli   HELP   ===
==============================

OPTION                                  DESCRIPTION
-h,  --help                             To show this help.
-c,  --compare                          To run compare and generate a patch file.
-ms, --migrate-to-source                To run migration applying all missing patch files to SOURCE CLIENT.
-mt, --migrate-to-target                To run migration applying all missing patch files to TARGET CLIENT.
-f,  --config-file                      To specify where to find config file, otherwise looks for 'pg-diff-config.json' on current working directory.
-p,  --patch-folder                     To set patch folder where save\retrieve patches (it will override configuration).
-s,  --save                             To save\register patch on migration history table without executing the script.

 TO COMPARE: pg-diff -c configuration-name script-name
    EXAMPLE: pg-diff -c development my-script

 TO MIGRATE: pg-diff [-ms | -mt] configuration-name
    EXAMPLE: pg-diff -ms development
    EXAMPLE: pg-diff -mt development

TO REGISTER: pg-diff -s configuration-name patch-file-name
    EXAMPLE: pg-diff -s development 20182808103040999_my-script.sql

This is the same command as above but with -c going first and -f going second. Maybe I'm misunderstanding how to provide the options.

I also noticed that the migration script will be written out relative to the working directory but it will also take the setting into account in the config file. I had configured it to ../../../ to undo the src/main/db it was located in. So the first time I ran it, pg-diff tried to write the migration script to the root :). Docs on the website still say "outputDirectory": "sqlscripts", //Folder relative to the position of the configuration file where to save sql scripts.

So not relative to the config file anymore, relative to the working dir.

michaelsogos commented 3 years ago

Dear @codemonstur

The CLI options cannot be mixed as you want 😄 . The -c option for example needs two following parameters, so that's why it give you back the error Missing or invalid arguments for option 'COMPARE'.

The output folder option should works like we discuss 😄. Anyway in the documentation v2.x (you read v1.x) I written "Absolute or relative directory path where save sql patches, in case of invalid values (like null, empty string, not a string) the current working directory will be used", take a look also at the end of the docs (i craeted a new section just for you 😄 )