From 88ceeaa2a5a79ab5376b2c5f48c28071a7aa0937 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 13 Apr 2017 00:04:35 +0100 Subject: [PATCH] Entry and journal: fix uniqueness to be composited, and not just by uid. Before this change, uid was unique on its own, this was wrong, because due to shared journals, we can have the same journal in two accounts, and we can thus have both journal and entry UIDs more than once. This fixes the constraint to be unique for journal, uid, and service, uid combinations. This is currently disabled for journals because of a bug in requery. --- .../com/etesync/syncadapter/model/JournalModel.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java index 96f8b415..1e1aaca2 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java +++ b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java @@ -15,16 +15,19 @@ import io.requery.ManyToOne; import io.requery.Persistable; import io.requery.PostLoad; import io.requery.ReferentialAction; +import io.requery.Table; import io.requery.sql.EntityDataStore; public class JournalModel { + // FIXME: Add unique constraint on the uid + service combination. Can't do it at the moment because requery is broken. @Entity + @Table(name = "Journal") public static abstract class Journal { @Key @Generated int id; - @Column(length = 64, unique = true, nullable = false) + @Column(length = 64, nullable = false) String uid; @Convert(CollectionInfoConverter.class) @@ -34,6 +37,7 @@ public class JournalModel { byte[] encryptedKey; + @Index(value = "uid_unique") long service; boolean deleted; @@ -102,18 +106,20 @@ public class JournalModel { } @Entity + @Table(name = "Entry", uniqueIndexes = "entry_unique_together") public static abstract class Entry { @Key @Generated int id; - @Column(length = 64, unique = true, nullable = false) + @Index("entry_unique_together") + @Column(length = 64, nullable = false) String uid; @Convert(SyncEntryConverter.class) SyncEntry content; - @Index("journal_index") + @Index("entry_unique_together") @ForeignKey(update = ReferentialAction.CASCADE) @ManyToOne Journal journal;