aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/plugin_exchangedb_postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c112
1 files changed, 63 insertions, 49 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index cda2df0d0..44096f17f 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -128,55 +128,6 @@ struct PostgresClosure
};
-
-
-/**
- * Drop all Taler tables. This should only be used by testcases.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param session database session to use
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static int
-postgres_drop_tables (void *cls,
- struct TALER_EXCHANGEDB_Session *session)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Dropping ALL tables\n");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS prewire;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS aggregation_tracking;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS deposits;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refresh_out;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refresh_commit_coin;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refresh_commit_link;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refunds;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refresh_order;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS refresh_sessions;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS known_coins;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS reserves_out;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS reserves_in;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS reserves;");
- SQLEXEC_ (session->conn,
- "DROP TABLE IF EXISTS denominations;");
- return GNUNET_OK;
- SQLEXEC_fail:
- return GNUNET_SYSERR;
-}
-
-
/**
* Function called by libpq whenever it wants to log something.
* We already log whenever we care, so this function does nothing
@@ -212,6 +163,69 @@ pq_notice_processor_cb (void *arg,
/**
+ * 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;
+ PGconn *conn;
+
+ conn = PQconnectdb (pc->connection_cfg_str);
+ if (CONNECTION_OK !=
+ PQstatus (conn))
+ {
+ TALER_LOG_ERROR ("Database connection failed: %s\n",
+ PQerrorMessage (conn));
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ PQsetNoticeReceiver (conn,
+ &pq_notice_receiver_cb,
+ NULL);
+ PQsetNoticeProcessor (conn,
+ &pq_notice_processor_cb,
+ NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Dropping ALL tables\n");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS prewire;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS aggregation_tracking;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS deposits;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS refresh_out;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS refresh_commit_coin;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS refresh_commit_link;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS refunds;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS refresh_order;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS refresh_sessions CASCADE;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS known_coins CASCADE;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS reserves_out;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS reserves_in;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS reserves;");
+ SQLEXEC_ (conn,
+ "DROP TABLE IF EXISTS denominations CASCADE;");
+ return GNUNET_OK;
+ SQLEXEC_fail:
+ return GNUNET_SYSERR;
+}
+
+
+/**
* Create the necessary tables if they are not present
*
* @param cls the `struct PostgresClosure` with the plugin-specific state