public inbox for [email protected]  
help / color / mirror / Atom feed
From: Dave Page <[email protected]>
To: Steve Chavez <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: CLI for Schema Diff
Date: Thu, 1 Apr 2021 09:44:36 +0100
Message-ID: <CA+OCxoy46obHYhsabNYuj3vhqD-F-oFQ8GfsE8rdB_Hqr4ALmw@mail.gmail.com> (raw)
In-Reply-To: <CAGRrpzbPk2bNmkoqb0NJCFYHLFQD9NusBmje+2gbuwvuETRHyQ@mail.gmail.com>
References: <CAGRrpzZp0XcKQjMyXpmxBnofapOqVhU4-6FzPGfXSw=-64HAvQ@mail.gmail.com>
	<CAGRrpzYy=6=Hms6hhJ2co6cJbzt9_1zaOAi5xgZJCfFBDL9jOg@mail.gmail.com>
	<CA+OCxoyjZhV9stFMAQ-QhHuA0+dLQD5XD_YT+Qo2vY0GhkBKFw@mail.gmail.com>
	<CAGRrpzbPk2bNmkoqb0NJCFYHLFQD9NusBmje+2gbuwvuETRHyQ@mail.gmail.com>

Hi

On Thu, Apr 1, 2021 at 12:38 AM Steve Chavez <[email protected]> wrote:

> > but is this something you'd be interested in working on to become a more
> fully featured and production quality CLI?
>
> Yes, absolutely!
>

Cool!


> What would be the next step? I'm all for doing a CLI that covers pgAdmin
> quality standards.
>

I think there are a few things we'd need to do:

1) Agree a standard for command line syntax. CLIs can easily become very
messy - I've spent time designing such standards in the past
(unfortunately, I can't just share that), but some thoughts might be:

  - have a consistent <command> <command options> <module> <action> <action
options> syntax. For example;

        pgacli --output-format=json schema-diff generate-diff --source=...
--target=...
        pgacli core register-server --host=... --maintenance-db=... ...
        pgacli grant-wizard grant-acl --select --type=tables
--objects=schema.tb_*

    (I've assumed a module name of 'core' for things directly related to
the heart of pgAdmin)

    - Actions are in the form "verb-noun"
    - Every common option has both a short and a long form
    - Uncommon options have a long form only
    - Support various help options, showing appropriate info;

    pgacli -h
    pgacli --help
    pgacli core -h
    pgacli schema-diff --help

2) Figure out how to avoid the hacks in your existing code to do things
like:

    - Hide initialisation output
    - Setup the dummy SQLite database

3) Make the code modular and extensible; perhaps using a Python module per
CLI module.

4) Allow the use of saved connections as well as arbitrary connection
strings.

I think 2 is the hardest issue. It may be that we add a flag to the main
application code that tells it it's running under the CLI, so that it can
avoid doing things it doesn't need to in those cases. One example is the
module loading; we might want to skip that entirely under the CLI, and have
the CLI module that's being called load just the modules it needs.


>
> On Wed, 31 Mar 2021 at 03:08, Dave Page <[email protected]> wrote:
>
>> Hi
>>
>> On Tue, Mar 30, 2021 at 3:36 PM Steve Chavez <[email protected]> wrote:
>>
>>> Hey all,
>>>
>>> In case anyone is interested, I've managed to enable a CLI mode for the
>>> Schema Diff on this repo:
>>>
>>> https://github.com/steve-chavez/pgadmin4/blob/cli/web/cli.py
>>>
>>> It basically works by using a Flask test client that interacts with the
>>> Schema Diff endpoints.
>>> It's a single isolated file, I haven't patched any of the existing
>>> modules.
>>>
>>> For a quickstart, there's also a docker image that can be used like:
>>>
>>> docker run supabase/pgadmin-schema-diff \
>>>   'postgres://postgres@host/diff_source' \
>>>   'postgres://postgres@host/diff_target' \
>>>   > diff.sql
>>> ## the stderr output shows the same messages as the Schema Diff GUI:
>>>
>>> Starting schema diff...
>>> Comparision started......0%
>>> Comparing FTS Dictionaries ...35%
>>> Comparing Functions ...50%
>>> Comparing Trigger Functions ...60%
>>> Comparing Sequences ...70%
>>> Comparing Tables ...80%
>>> Comparing Views ...90%
>>> Done.
>>>
>>>
>> That's an interesting approach! Obviously the code is just a proof of
>> concept at the moment (redirecting stdout is masking errors for example),
>> but is this something you'd be interested in working on to become a more
>> fully featured and production quality CLI?
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EDB: http://www.enterprisedb.com
>>
>>

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EDB: http://www.enterprisedb.com


view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: CLI for Schema Diff
  In-Reply-To: <CA+OCxoy46obHYhsabNYuj3vhqD-F-oFQ8GfsE8rdB_Hqr4ALmw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox