From 8e8c83b83c7b0d61b1f05d90bd828f288af2966e Mon Sep 17 00:00:00 2001 From: akwizgran Date: Mon, 1 Aug 2011 17:37:48 +0100 Subject: [PATCH] Use the combination of batch ID and contact ID as the primary key for received and sent batches, since batches sent to or received from different contacts may contain identical lists of messages and therefore have identical IDs. --- components/net/sf/briar/db/JdbcDatabase.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/net/sf/briar/db/JdbcDatabase.java b/components/net/sf/briar/db/JdbcDatabase.java index c39df44f6..c09508ad2 100644 --- a/components/net/sf/briar/db/JdbcDatabase.java +++ b/components/net/sf/briar/db/JdbcDatabase.java @@ -93,7 +93,7 @@ abstract class JdbcDatabase implements Database { "CREATE TABLE batchesToAck" + " (batchId HASH NOT NULL," + " contactId INT NOT NULL," - + " PRIMARY KEY (batchId)," + + " PRIMARY KEY (batchId, contactId)," + " FOREIGN KEY (contactId) REFERENCES contacts (contactId)" + " ON DELETE CASCADE)"; @@ -113,7 +113,7 @@ abstract class JdbcDatabase implements Database { + " contactId INT NOT NULL," + " timestamp TIMESTAMP NOT NULL," + " passover INT NOT NULL," - + " PRIMARY KEY (batchId)," + + " PRIMARY KEY (batchId, contactId)," + " FOREIGN KEY (contactId) REFERENCES contacts (contactId)" + " ON DELETE CASCADE)"; @@ -123,9 +123,8 @@ abstract class JdbcDatabase implements Database { + " contactId INT NOT NULL," + " messageId HASH NOT NULL," + " PRIMARY KEY (batchId, messageId)," - + " FOREIGN KEY (batchId) REFERENCES outstandingBatches (batchId)" - + " ON DELETE CASCADE," - + " FOREIGN KEY (contactId) REFERENCES contacts (contactId)" + + " FOREIGN KEY (batchId, contactId)" + + " REFERENCES outstandingBatches (batchId, contactId)" + " ON DELETE CASCADE," + " FOREIGN KEY (messageId) REFERENCES messages (messageId)" + " ON DELETE CASCADE)";