From: Jonathan McDowell Date: Sun, 3 Jul 2022 10:16:14 +0000 (+0100) Subject: Fix deletion of keys with PostgreSQL backend X-Git-Tag: onak-0.6.2~5 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=67f26da9c26e544b723ac73ac67383519c873e30;p=onak.git Fix deletion of keys with PostgreSQL backend In pg_delete_key() we deleted the key from onak_keys as the first action, which would fail because the other tables had a reference to that object via a foreign key relation. The correct approach is to delete the key itself last, after the signature and UID tables have had their entries deleted. --- diff --git a/keydb/keydb_pg.c b/keydb/keydb_pg.c index 52d27fc..1b58c1a 100644 --- a/keydb/keydb_pg.c +++ b/keydb/keydb_pg.c @@ -290,19 +290,19 @@ static int pg_delete_key(struct onak_dbctx *dbctx, PQclear(result); snprintf(statement, 1023, - "DELETE FROM onak_keys WHERE keyid = '%" PRIX64 "'", + "DELETE FROM onak_sigs WHERE signee = '%" PRIX64 "'", keyid); result = PQexec(dbconn, statement); PQclear(result); snprintf(statement, 1023, - "DELETE FROM onak_sigs WHERE signee = '%" PRIX64 "'", + "DELETE FROM onak_uids WHERE keyid = '%" PRIX64 "'", keyid); result = PQexec(dbconn, statement); PQclear(result); snprintf(statement, 1023, - "DELETE FROM onak_uids WHERE keyid = '%" PRIX64 "'", + "DELETE FROM onak_keys WHERE keyid = '%" PRIX64 "'", keyid); result = PQexec(dbconn, statement); } else if (PQresultStatus(result) != PGRES_TUPLES_OK) {