cli/db: Open a `swh db shell` subcommand
This will ease database introspection from a pod toolbox without the need to configure extra specific postgresql.
swh@swh-toolbox-66c568b6d5-7tzzs:~$ swh db shell --help
WARNING:swh.core.sentry:Sentry DSN not provided, events will not be sent.
Usage: swh db shell [OPTIONS] MODULE
A subcommand to ease starting a psql shell using swh module configuration
file. This may be useful for extra troubleshooting session when the other
'swh db' clis are not enough.
Options:
-d, --dbname, --db-name TEXT Database name or connection URI.
--module-config-key TEXT Module config key to lookup.
-h, --help Show this message and exit.
Tested live in a pod (copied file to the pod and enjoy):
$ (local) kubectl --context archive-staging-rke2 cp ./swh/core/cli/db.py swh-cassandra-next-version/swh-toolbox-66c568b6d5-7tzzs:/opt/swh/.local/lib/python3.10/site-packages/swh/core/cli/db.py
----
swh@swh-toolbox-66c568b6d5-7tzzs:~$ export SWH_CONFIG_FILENAME=/etc/swh/config-scheduler.yml
swh@swh-toolbox-66c568b6d5-7tzzs:~$ swh db shell scheduler
WARNING:swh.core.sentry:Sentry DSN not provided, events will not be sent.
psql (13.14 (Debian 13.14-0+deb11u1), server 12.19 (Debian 12.19-1.pgdg110+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
swh-scheduler=> \conninfo
You are connected to database "swh-scheduler" as user "swh-scheduler" on host "db1.internal.staging.swh.network" (address "192.168.130.11") at port "5432".
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Edited by Antoine R. Dumont