26.32. kych-dbinit(1)#

26.32.1. Name#

kych-dbinit - initialise and upgrade the KyCH database schema

26.32.2. Synopsis#

kych-dbinit [-c CONFIG] [-L LEVEL] [-v] [–sql-dir DIR] [-n | –dry-run] [–print-connection]

26.32.3. Description#

kych-dbinit creates the oauth2gw schema that kych-oauth2-gateway(1) works on, and brings an existing one up to the patch level of the installed SQL files. Both are the same operation: every schema change is a numbered patch file, oauth2gw-000N.sql, which registers itself with the Versioning bookkeeping in the _v schema, and this tool applies those patches the database does not have yet, in ascending order, each in its own transaction.

It is idempotent: running it against a database that is already current changes nothing and succeeds. That is what makes it safe to run unattended, which the Debian package does from its postinst on every upgrade, so that a newly installed patch is applied before the service is restarted.

It does not create the database or the role that owns it; kych-dbconfig(1) does that once, and calls this tool afterwards.

26.32.4. Options#

-c CONFIG | –config=CONFIG

Use the configuration file CONFIG. Without it the standard search path applies, ending at /etc/kych/kych.conf; see kych.conf(5). The database to act on is the DATABASE option in it. DATABASE and SQL_DIR are all that is read: a configuration that the gateway itself would refuse, such as one not yet rewritten after an upgrade, does not keep the schema from being brought up to date.

-L LEVEL | –log=LEVEL

Set the logging verbosity: ERROR, WARN, INFO, DEBUG or TRACE, or the numbers 1 to 5. Defaults to INFO.

-v | –verbose

Also log what the libraries have to say, sqlx in particular, which is the way to see the statements this tool runs.

–sql-dir=DIR

Read versioning.sql and the oauth2gw-*.sql patches from DIR instead of the SQL_DIR of the configuration, which defaults to $DATADIR/sql – /usr/share/kych/sql for the Debian package.

-n | –dry-run

Report which patches would be applied and change nothing. Note that in a database without the _v bookkeeping every patch is reported as pending, since there is nothing yet to say otherwise.

–print-connection

Print the connection the configuration names as PGDATABASE, PGHOST and PGPORT assignments for a shell to eval, and exit without connecting. kych-dbconfig(1) uses this instead of parsing kych.conf(5) itself, which is what makes it work against a PostgreSQL that is not on the default port.

-h | –help

Print short help.

–version

Print version information.

26.32.5. Exit Status#

0

The database is at the latest patch level, whether or not anything had to be applied.

2

There is no database to work on: it does not exist, or the server is not listening where the configuration says it is. The Debian package’s postinst treats this as the expected state of a first install, where kych-dbconfig(1) has not run yet, and does not fail the installation over it.

1

Anything else: the configuration could not be loaded, the connection was refused for a reason of its own, or a patch failed. A failing patch is rolled back, so the database keeps the patch level it had.

26.32.6. Examples#

Apply whatever is pending, as the user the daemon runs as:

$ sudo -u kych kych-dbinit -c /etc/kych/kych.conf

Check before an upgrade what it would do:

$ sudo -u kych kych-dbinit -c /etc/kych/kych.conf --dry-run

26.32.7. See Also#

kych-dbconfig(1), kych-oauth2-gateway(1), kych-client-management(1), kych.conf(5).

26.32.8. Bugs#

Report bugs by using https://bugs.taler.net/ or by sending electronic mail to <taler@gnu.org>.