summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-25 21:55:45 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-25 21:55:45 +0200
commit23750b7d0622c7080ff8acde2b623568b98a88f4 (patch)
tree55f70bb07278834487181784e8881cf210eae7fb /src/backenddb
parent338895460158b98d3f8dfc4512e6b8d165d1aae5 (diff)
downloadmerchant-23750b7d0622c7080ff8acde2b623568b98a88f4.tar.gz
merchant-23750b7d0622c7080ff8acde2b623568b98a88f4.tar.bz2
merchant-23750b7d0622c7080ff8acde2b623568b98a88f4.zip
misc. fixes
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/drop0001.sql26
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c46
2 files changed, 61 insertions, 11 deletions
diff --git a/src/backenddb/drop0001.sql b/src/backenddb/drop0001.sql
index 4a1b3ecc..b3ce6b42 100644
--- a/src/backenddb/drop0001.sql
+++ b/src/backenddb/drop0001.sql
@@ -25,19 +25,27 @@ BEGIN;
-- Drops for 0001.sql
-DROP TABLE IF EXISTS merchant_transfers CASCADE;
-DROP TABLE IF EXISTS merchant_deposits CASCADE;
-DROP TABLE IF EXISTS merchant_transactions CASCADE;
-DROP TABLE IF EXISTS merchant_proofs CASCADE;
+DROP TABLE IF EXISTS merchant_exchange_wire_fees CASCADE;
+DROP TABLE IF EXISTS merchant_exchange_signing_keys CASCADE;
+DROP TABLE IF EXISTS merchant_instances CASCADE;
+DROP TABLE IF EXISTS merchant_keys CASCADE;
+DROP TABLE IF EXISTS merchant_accounts CASCADE;
+DROP TABLE IF EXISTS merchant_inventory CASCADE;
+DROP TABLE IF EXISTS merchant_inventory_locks CASCADE;
+DROP TABLE IF EXISTS merchant_accounts CASCADE;
+DROP TABLE IF EXISTS merchant_orders CASCADE;
+DROP TABLE IF EXISTS merchant_order_locks CASCADE;
DROP TABLE IF EXISTS merchant_contract_terms CASCADE;
+DROP TABLE IF EXISTS merchant_deposits CASCADE;
DROP TABLE IF EXISTS merchant_refunds CASCADE;
-DROP TABLE IF EXISTS exchange_wire_fees CASCADE;
+DROP TABLE IF EXISTS merchant_credits CASCADE;
+DROP TABLE IF EXISTS merchant_transfer_signatures CASCADE;
+DROP TABLE IF EXISTS merchant_transfer_by_coin CASCADE;
+DROP TABLE IF EXISTS merchant_tip_reserves CASCADE;
+DROP TABLE IF EXISTS merchant_tip_reserve_keys CASCADE;
DROP TABLE IF EXISTS merchant_tips CASCADE;
DROP TABLE IF EXISTS merchant_tip_pickups CASCADE;
-DROP TABLE IF EXISTS merchant_tip_reserve_credits CASCADE;
-DROP TABLE IF EXISTS merchant_tip_reserves CASCADE;
-DROP TABLE IF EXISTS merchant_orders CASCADE;
-DROP TABLE IF EXISTS merchant_session_info CASCADE;
+DROP TABLE IF EXISTS merchant_tip_pickup_signatures CASCADE;
-- Drop versioning (0000.sql)
DROP SCHEMA IF EXISTS _v CASCADE;
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index c12978ae..57da9811 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -845,7 +845,7 @@ postgres_lookup_product (void *cls,
&pd->price),
TALER_PQ_result_spec_json ("taxes",
&pd->taxes),
- GNUNET_PQ_result_spec_uint64 ("total_stocked",
+ GNUNET_PQ_result_spec_uint64 ("total_stock",
&pd->total_stocked),
GNUNET_PQ_result_spec_uint64 ("total_sold",
&pd->total_sold),
@@ -1029,6 +1029,37 @@ postgres_lock_product (void *cls,
}
+/**
+ * Delete information about an order. Note that the transaction must
+ * enforce that the order is not awaiting payment anymore.
+ *
+ * @param cls closure
+ * @param instance_id instance to delete order of
+ * @param order_id order to delete
+ * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ * if pending payment prevents deletion OR order unknown
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_delete_order (void *cls,
+ const char *instance_id,
+ const char *order_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_string (order_id),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "delete_order",
+ params);
+}
+
+
/* ********************* OLD API ************************** */
/**
@@ -4128,7 +4159,17 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" FROM merchant_order_locks"
" WHERE product_serial=ps.product_serial)",
5),
-
+ /* for postgres_delete_order() */
+ GNUNET_PQ_make_prepare ("delete_order",
+ "DELETE"
+ " FROM merchant_orders"
+ " WHERE merchant_inventory.merchant_serial="
+ " (SELECT merchant_serial "
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)"
+ " AND merchant_orders.order_id=$2"
+ " AND pay_deadline < $3",
+ 3),
/* OLD API: */
#if 0
GNUNET_PQ_make_prepare ("insert_deposit",
@@ -4638,6 +4679,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->insert_product = &postgres_insert_product;
plugin->update_product = &postgres_update_product;
plugin->lock_product = &postgres_lock_product;
+ plugin->delete_order = &postgres_delete_order;
/* old API: */
plugin->store_deposit = &postgres_store_deposit;