aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <sreeharsha@totakura.in>2015-04-29 12:40:59 +0200
committerSree Harsha Totakura <sreeharsha@totakura.in>2015-04-29 12:40:59 +0200
commit3f3d8dfbfb6d9271c5458f656eaa51934dd00156 (patch)
tree2ae1d2ac32ef4216f5a68039b46d13ad010c3597
parent211cd3cdb7e132b5be859cb4ad4f9f46b58c7b68 (diff)
mintdb postgres: enforce foreign key on denominations
-rw-r--r--src/mintdb/plugin_mintdb_postgres.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c
index cd8987389..772b8342e 100644
--- a/src/mintdb/plugin_mintdb_postgres.c
+++ b/src/mintdb/plugin_mintdb_postgres.c
@@ -178,7 +178,10 @@ postgres_create_tables (void *cls,
}
#define SQLEXEC(sql) SQLEXEC_(conn, sql, result);
/* Denomination table for holding the publicly available information of
- denominations keys */
+ denominations keys. The denominations are to be referred to by using
+ foreign keys. The denominations are deleted by a housekeeping tool;
+ hence, do not use `ON DELETE CASCASE' on these rows in the tables
+ referencing these rows */
SQLEXEC ("CREATE TABLE IF NOT EXISTS denominations"
"("
" pub BYTEA PRIMARY KEY"
@@ -222,17 +225,18 @@ postgres_create_tables (void *cls,
SQLEXEC ("CREATE TABLE IF NOT EXISTS collectable_blindcoins"
"("
"blind_ev BYTEA PRIMARY KEY"
- ",denom_pub BYTEA NOT NULL" /* FIXME: Make this a foreign key? */
+ ",denom_pub BYTEA NOT NULL REFERENCES denominations (pub)"
",denom_sig BYTEA NOT NULL"
",reserve_pub BYTEA REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
",reserve_sig BYTEA NOT NULL"
");");
+ /* Index blindcoins(reserve_pub) for get_reserves_blindcoins statement */
SQLEXEC ("CREATE INDEX collectable_blindcoins_reserve_pub_index ON"
" collectable_blindcoins (reserve_pub)");
SQLEXEC("CREATE TABLE IF NOT EXISTS known_coins "
"("
" coin_pub BYTEA NOT NULL PRIMARY KEY"
- ",denom_pub BYTEA NOT NULL"
+ ",denom_pub BYTEA NOT NULL REFERENCES denominations (pub)"
",denom_sig BYTEA NOT NULL"
",expended_value INT8 NOT NULL"
",expended_fraction INT4 NOT NULL"
@@ -301,7 +305,7 @@ postgres_create_tables (void *cls,
"( "
/* FIXME #3769: the following primary key may be too restrictive */
" coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (length(coin_pub)=32)"
- ",denom_pub BYTEA NOT NULL" /* FIXME: Link this as a foreign key? */
+ ",denom_pub BYTEA NOT NULL REFERENCES denominations (pub)"
",denom_sig BYTEA NOT NULL"
",transaction_id INT8 NOT NULL"
",amount_currency VARCHAR(4) NOT NULL"
@@ -1513,8 +1517,8 @@ postgres_insert_deposit (void *cls,
&deposit->amount_with_fee);
struct TALER_PQ_QueryParam params[]= {
TALER_PQ_QUERY_PARAM_PTR (&deposit->coin.coin_pub),
- TALER_PQ_QUERY_PARAM_PTR_SIZED (denom_pub_enc, denom_pub_enc_size),
- TALER_PQ_QUERY_PARAM_PTR_SIZED (denom_sig_enc, denom_sig_enc_size),
+ TALER_PQ_QUERY_PARAM_PTR_SIZED (denom_pub_enc, denom_pub_enc_size -1),
+ TALER_PQ_QUERY_PARAM_PTR_SIZED (denom_sig_enc, denom_sig_enc_size -1),
TALER_PQ_QUERY_PARAM_PTR (&deposit->transaction_id),
TALER_PQ_QUERY_PARAM_PTR (&amount_nbo.value),
TALER_PQ_QUERY_PARAM_PTR (&amount_nbo.fraction),