commit 370de45652f9b3cf88d1ffd053d32af48e07b12e
parent 82af0bc97507eb3a7e89b4d7f66ba968419fea30
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 14 Jun 2026 01:43:39 +0200
re-add check to refuse to start if schema is not current
Diffstat:
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/src/include/anastasis_database_lib.h b/src/include/anastasis_database_lib.h
@@ -69,7 +69,20 @@
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
enum GNUNET_GenericReturnValue
-ANASTASIS_DB_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
+ANASTASIS_DB_init (
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Initialize the Anastasis database subsystem for administration.
+ * Disables the check that the database schema is current.
+ *
+ * @param cfg configuration to use
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+enum GNUNET_GenericReturnValue
+ANASTASIS_DB_init_admin (
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
/**
diff --git a/src/stasis/anastasis-db_pg.c b/src/stasis/anastasis-db_pg.c
@@ -174,8 +174,16 @@ reconnect_cb (void *cls,
}
-enum GNUNET_GenericReturnValue
-ANASTASIS_DB_init (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 enum GNUNET_GenericReturnValue
+do_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool check_current)
{
pg = GNUNET_new (struct PostgresClosure);
pg->cfg = cfg;
@@ -201,10 +209,36 @@ ANASTASIS_DB_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
ANASTASIS_DB_fini ();
return GNUNET_SYSERR;
}
+ if (check_current &&
+ (GNUNET_OK !=
+ GNUNET_PQ_check_current (pg->conn,
+ "stasis-")) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database schema is not up-to-date. Try running anastasis-dbinit or anastasis-dbconfig!\n");
+ ANASTASIS_DB_fini ();
+ return GNUNET_NO;
+ }
return GNUNET_OK;
}
+enum GNUNET_GenericReturnValue
+ANASTASIS_DB_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ return do_init (cfg,
+ true);
+}
+
+
+enum GNUNET_GenericReturnValue
+ANASTASIS_DB_init_admin (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ return do_init (cfg,
+ false);
+}
+
+
void
ANASTASIS_DB_fini (void)
{
diff --git a/src/stasis/anastasis-dbinit.c b/src/stasis/anastasis-dbinit.c
@@ -54,7 +54,7 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (GNUNET_OK !=
- ANASTASIS_DB_init (cfg))
+ ANASTASIS_DB_init_admin (cfg))
{
fprintf (stderr,
"Failed to initialize database.\n");