summaryrefslogtreecommitdiff
path: root/src/backenddb/plugin_merchantdb_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-02 20:40:11 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-02 20:40:11 +0100
commit7334cfc40995c98aa550fedc7b249d9c08100028 (patch)
tree27ee7cc6ed6fe18615fff32f67b3839de84c7805 /src/backenddb/plugin_merchantdb_postgres.c
parentfeb6c3c694f6f083d7b8d09a35f2074d5c3d44f4 (diff)
downloadmerchant-7334cfc40995c98aa550fedc7b249d9c08100028.tar.gz
merchant-7334cfc40995c98aa550fedc7b249d9c08100028.tar.bz2
merchant-7334cfc40995c98aa550fedc7b249d9c08100028.zip
fix DB initialization logic to avoid CREATE table attempts in taler-merchant-httpd
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 47147c07..5954e3c6 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -105,28 +105,50 @@ struct PostgresClosure
};
-/* ********************* NEW API ************************** */
+/**
+ * Drop all Taler tables. This should only be used by testcases.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+static int
+postgres_drop_tables (void *cls)
+{
+ struct PostgresClosure *pc = cls;
+ struct GNUNET_PQ_Context *conn;
+
+ conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "merchantdb-postgres",
+ "drop",
+ NULL,
+ NULL);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ GNUNET_PQ_disconnect (conn);
+ return GNUNET_OK;
+}
/**
- * Drop merchant tables
+ * Initialize tables.
*
- * @param cls closure our `struct Plugin`
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static int
-postgres_drop_tables (void *cls)
+postgres_create_tables (void *cls)
{
- struct PostgresClosure *pg = cls;
- char *load_path;
-
- GNUNET_asprintf (&load_path,
- "%s%s",
- pg->sql_dir,
- "drop");
- GNUNET_PQ_run_sql (pg->conn,
- load_path);
- GNUNET_free (load_path);
+ struct PostgresClosure *pc = cls;
+ struct GNUNET_PQ_Context *conn;
+
+ conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "merchantdb-postgres",
+ "merchant-",
+ NULL,
+ NULL);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ GNUNET_PQ_disconnect (conn);
return GNUNET_OK;
}
@@ -6015,12 +6037,10 @@ postgres_insert_pickup_blind_signature (
* Establish connection to the database.
*
* @param cls plugin context
- * @param for_drop is this to drop/reset the database (so no point in
- * preparing statements)?
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static int
-postgres_connect (void *cls,
- bool for_drop)
+postgres_connect (void *cls)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_PreparedStatement ps[] = {
@@ -8396,11 +8416,9 @@ postgres_connect (void *cls,
pg->conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"merchantdb-postgres",
- "merchant-",
NULL,
- for_drop
- ? NULL
- : ps);
+ NULL,
+ ps);
if (NULL == pg->conn)
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -8446,6 +8464,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin = GNUNET_new (struct TALER_MERCHANTDB_Plugin);
plugin->cls = pg;
plugin->connect = &postgres_connect;
+ plugin->create_tables = &postgres_create_tables;
plugin->drop_tables = &postgres_drop_tables;
plugin->preflight = &postgres_preflight;
plugin->start = &postgres_start;