donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit ffaa971d49be732296685dd5134d48360215a24b
parent ea173d45369720d38fe0391e4a84f0b655fed1d3
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 14 Jun 2026 01:13:45 +0200

re-add check to refuse to start if schema is not current

Diffstat:
Msrc/donau-tools/donau-dbinit.c | 2+-
Msrc/donaudb/plugin_donaudb_postgres.c | 40++++++++++++++++++++++++++++++++++++++--
Msrc/include/donaudb_lib.h | 17++++++++++-------
3 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/src/donau-tools/donau-dbinit.c b/src/donau-tools/donau-dbinit.c @@ -83,7 +83,7 @@ run (void *cls, (void) args; (void) cfgfile; if (NULL == - (ctx = DONAUDB_connect (cfg))) + (ctx = DONAUDB_connect_admin (cfg))) { fprintf (stderr, "Failed to initialize database ctx.\n"); diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -117,8 +117,16 @@ internal_setup (struct DONAUDB_PostgresContext *pg) } -struct DONAUDB_PostgresContext * -DONAUDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) +/** + * Initialize the database connection. + * + * @param cfg configuration to use + * @param check_current true to check if the database schema is current + * @return NULL on failure + */ +static struct DONAUDB_PostgresContext * +do_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + bool check_current) { struct DONAUDB_PostgresContext *pg; @@ -145,6 +153,16 @@ DONAUDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) if (GNUNET_OK != internal_setup (pg)) goto fail; + if (check_current && + (GNUNET_OK != + GNUNET_PQ_check_current (pg->conn, + "donau-")) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Database schema is not up-to-date. Try running donau-dbinit or donau-dbconfig!\n"); + goto fail; + } + return pg; fail: DONAUDB_disconnect (pg); @@ -152,6 +170,24 @@ fail: } +struct DONAUDB_PostgresContext * +DONAUDB_connect ( + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + return do_connect (cfg, + true); +} + + +struct DONAUDB_PostgresContext * +DONAUDB_connect_admin ( + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + return do_connect (cfg, + false); +} + + void DONAUDB_disconnect (struct DONAUDB_PostgresContext *pg) { diff --git a/src/include/donaudb_lib.h b/src/include/donaudb_lib.h @@ -150,23 +150,26 @@ struct DONAUDB_DonationUnitKey /** - * Connect to the database if the connection does not exist yet. + * Connect to the donau database. * - * @param pg the plugin-specific state - * @return #GNUNET_OK on success + * @param cfg configuration to use + * @return NULL on failure */ -enum GNUNET_GenericReturnValue -DONAUDB_internal_setup (struct DONAUDB_PostgresContext *pg); +struct DONAUDB_PostgresContext * +DONAUDB_connect ( + const struct GNUNET_CONFIGURATION_Handle *cfg); /** - * Connect to the donau database. + * Connect to the donau database for administration. + * Disables the check that the database schema is current. * * @param cfg configuration to use * @return NULL on failure */ struct DONAUDB_PostgresContext * -DONAUDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); +DONAUDB_connect_admin ( + const struct GNUNET_CONFIGURATION_Handle *cfg); /**