commit 2c81efb092330a1ef80b7a7f6742f7b011a10691
parent 98a06e7b1280a56f0c36b5aa91d36c9a71f819bb
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 14 Jun 2026 01:13:36 +0200
re-add check to refuse to start if schema is not current
Diffstat:
3 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c
@@ -99,7 +99,7 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
- pg = TALER_EXCHANGEDB_connect (cfg);
+ pg = TALER_EXCHANGEDB_connect_admin (cfg);
if (NULL == pg)
{
fprintf (stderr,
diff --git a/src/exchangedb/pg.c b/src/exchangedb/pg.c
@@ -130,8 +130,16 @@ internal_setup (struct TALER_EXCHANGEDB_PostgresContext *pg)
}
-struct TALER_EXCHANGEDB_PostgresContext *
-TALER_EXCHANGEDB_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 TALER_EXCHANGEDB_PostgresContext *
+do_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool check_current)
{
struct TALER_EXCHANGEDB_PostgresContext *pg;
unsigned long long dpl;
@@ -231,6 +239,15 @@ TALER_EXCHANGEDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
goto fail;
}
+ if (check_current &&
+ (GNUNET_OK !=
+ GNUNET_PQ_check_current (pg->conn,
+ "exchange-")) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database schema is not up-to-date. Try running taler-exchange-dbinit or taler-exchange-dbconfig!\n");
+ goto fail;
+ }
return pg;
fail:
@@ -240,6 +257,24 @@ fail:
}
+struct TALER_EXCHANGEDB_PostgresContext *
+TALER_EXCHANGEDB_connect (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ return do_connect (cfg,
+ true);
+}
+
+
+struct TALER_EXCHANGEDB_PostgresContext *
+TALER_EXCHANGEDB_connect_admin (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ return do_connect (cfg,
+ false);
+}
+
+
void
TALER_EXCHANGEDB_disconnect (struct TALER_EXCHANGEDB_PostgresContext *pg)
{
diff --git a/src/include/exchangedb_lib.h b/src/include/exchangedb_lib.h
@@ -891,7 +891,20 @@ typedef void
* @return NULL on failure
*/
struct TALER_EXCHANGEDB_PostgresContext *
-TALER_EXCHANGEDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
+TALER_EXCHANGEDB_connect (
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Initialize the database connection for administration.
+ * Disables the check that the database schema is current.
+ *
+ * @param cfg configuration to use
+ * @return NULL on failure
+ */
+struct TALER_EXCHANGEDB_PostgresContext *
+TALER_EXCHANGEDB_connect_admin (
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
/**