From: AsamK Date: Tue, 23 Aug 2022 17:41:02 +0000 (+0200) Subject: Create database tables with strict mode X-Git-Tag: v0.11.0~10 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/adcc88823f68decc92646e1d44ce11ba9b5de54c?hp=280d8d7f10e7d6e6068545c4d5fce0bbbb96a2ea Create database tables with strict mode --- diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/AccountDatabase.java b/lib/src/main/java/org/asamk/signal/manager/storage/AccountDatabase.java index 5093b9be..3c168860 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/AccountDatabase.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/AccountDatabase.java @@ -64,9 +64,9 @@ public class AccountDatabase extends Database { color TEXT, expiration_time INTEGER NOT NULL DEFAULT 0, - blocked BOOLEAN NOT NULL DEFAULT FALSE, - archived BOOLEAN NOT NULL DEFAULT FALSE, - profile_sharing BOOLEAN NOT NULL DEFAULT FALSE, + blocked INTEGER NOT NULL DEFAULT FALSE, + archived INTEGER NOT NULL DEFAULT FALSE, + profile_sharing INTEGER NOT NULL DEFAULT FALSE, profile_last_update_timestamp INTEGER NOT NULL DEFAULT 0, profile_given_name TEXT, @@ -77,7 +77,7 @@ public class AccountDatabase extends Database { profile_mobile_coin_address BLOB, profile_unidentified_access_mode TEXT, profile_capabilities TEXT - ); + ) STRICT; """); } } @@ -89,8 +89,8 @@ public class AccountDatabase extends Database { _id INTEGER PRIMARY KEY, pack_id BLOB UNIQUE NOT NULL, pack_key BLOB NOT NULL, - installed BOOLEAN NOT NULL DEFAULT FALSE - ); + installed INTEGER NOT NULL DEFAULT FALSE + ) STRICT; """); } } @@ -107,7 +107,7 @@ public class AccountDatabase extends Database { signature BLOB NOT NULL, timestamp INTEGER DEFAULT 0, UNIQUE(account_id_type, key_id) - ); + ) STRICT; CREATE TABLE pre_key ( _id INTEGER PRIMARY KEY, account_id_type INTEGER NOT NULL, @@ -115,7 +115,7 @@ public class AccountDatabase extends Database { public_key BLOB NOT NULL, private_key BLOB NOT NULL, UNIQUE(account_id_type, key_id) - ); + ) STRICT; """); } } @@ -129,9 +129,9 @@ public class AccountDatabase extends Database { master_key BLOB NOT NULL, group_data BLOB, distribution_id BLOB UNIQUE NOT NULL, - blocked BOOLEAN NOT NULL DEFAULT FALSE, - permission_denied BOOLEAN NOT NULL DEFAULT FALSE - ); + blocked INTEGER NOT NULL DEFAULT FALSE, + permission_denied INTEGER NOT NULL DEFAULT FALSE + ) STRICT; CREATE TABLE group_v1 ( _id INTEGER PRIMARY KEY, group_id BLOB UNIQUE NOT NULL, @@ -139,15 +139,15 @@ public class AccountDatabase extends Database { name TEXT, color TEXT, expiration_time INTEGER NOT NULL DEFAULT 0, - blocked BOOLEAN NOT NULL DEFAULT FALSE, - archived BOOLEAN NOT NULL DEFAULT FALSE - ); + blocked INTEGER NOT NULL DEFAULT FALSE, + archived INTEGER NOT NULL DEFAULT FALSE + ) STRICT; CREATE TABLE group_v1_member ( _id INTEGER PRIMARY KEY, group_id INTEGER NOT NULL REFERENCES group_v1 (_id) ON DELETE CASCADE, recipient_id INTEGER NOT NULL REFERENCES recipient (_id) ON DELETE CASCADE, UNIQUE(group_id, recipient_id) - ); + ) STRICT; """); } } @@ -162,7 +162,7 @@ public class AccountDatabase extends Database { device_id INTEGER NOT NULL, record BLOB NOT NULL, UNIQUE(account_id_type, recipient_id, device_id) - ); + ) STRICT; """); } } @@ -176,7 +176,7 @@ public class AccountDatabase extends Database { identity_key BLOB NOT NULL, added_timestamp INTEGER NOT NULL, trust_level INTEGER NOT NULL - ); + ) STRICT; """); } } @@ -192,7 +192,7 @@ public class AccountDatabase extends Database { record BLOB NOT NULL, created_timestamp INTEGER NOT NULL, UNIQUE(recipient_id, device_id, distribution_id) - ); + ) STRICT; CREATE TABLE sender_key_shared ( _id INTEGER PRIMARY KEY, recipient_id INTEGER NOT NULL REFERENCES recipient (_id) ON DELETE CASCADE, @@ -200,7 +200,7 @@ public class AccountDatabase extends Database { distribution_id BLOB NOT NULL, timestamp INTEGER NOT NULL, UNIQUE(recipient_id, device_id, distribution_id) - ); + ) STRICT; """); } } @@ -208,7 +208,7 @@ public class AccountDatabase extends Database { logger.debug("Updating database: Adding urgent field"); try (final var statement = connection.createStatement()) { statement.executeUpdate(""" - ALTER TABLE message_send_log_content ADD COLUMN urgent BOOLEAN NOT NULL DEFAULT TRUE; + ALTER TABLE message_send_log_content ADD COLUMN urgent INTEGER NOT NULL DEFAULT TRUE; """); } } diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java index e9db58f0..538ff294 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java @@ -52,9 +52,9 @@ public class GroupStore { master_key BLOB NOT NULL, group_data BLOB, distribution_id BLOB UNIQUE NOT NULL, - blocked BOOLEAN NOT NULL DEFAULT FALSE, - permission_denied BOOLEAN NOT NULL DEFAULT FALSE - ); + blocked INTEGER NOT NULL DEFAULT FALSE, + permission_denied INTEGER NOT NULL DEFAULT FALSE + ) STRICT; CREATE TABLE group_v1 ( _id INTEGER PRIMARY KEY, group_id BLOB UNIQUE NOT NULL, @@ -62,15 +62,15 @@ public class GroupStore { name TEXT, color TEXT, expiration_time INTEGER NOT NULL DEFAULT 0, - blocked BOOLEAN NOT NULL DEFAULT FALSE, - archived BOOLEAN NOT NULL DEFAULT FALSE - ); + blocked INTEGER NOT NULL DEFAULT FALSE, + archived INTEGER NOT NULL DEFAULT FALSE + ) STRICT; CREATE TABLE group_v1_member ( _id INTEGER PRIMARY KEY, group_id INTEGER NOT NULL REFERENCES group_v1 (_id) ON DELETE CASCADE, recipient_id INTEGER NOT NULL REFERENCES recipient (_id) ON DELETE CASCADE, UNIQUE(group_id, recipient_id) - ); + ) STRICT; """); } } diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/PreKeyStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/PreKeyStore.java index 205f4fa3..a70c6b8c 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/PreKeyStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/PreKeyStore.java @@ -35,7 +35,7 @@ public class PreKeyStore implements org.signal.libsignal.protocol.state.PreKeySt public_key BLOB NOT NULL, private_key BLOB NOT NULL, UNIQUE(account_id_type, key_id) - ); + ) STRICT; """); } } diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/SignedPreKeyStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/SignedPreKeyStore.java index 6c8787c9..722bb56c 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/SignedPreKeyStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/prekeys/SignedPreKeyStore.java @@ -32,14 +32,14 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si statement.executeUpdate(""" CREATE TABLE signed_pre_key ( _id INTEGER PRIMARY KEY, - account_id_type BLOB NOT NULL, + account_id_type INTEGER NOT NULL, key_id INTEGER NOT NULL, public_key BLOB NOT NULL, private_key BLOB NOT NULL, signature BLOB NOT NULL, timestamp INTEGER DEFAULT 0, UNIQUE(account_id_type, key_id) - ); + ) STRICT; """); } } diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java index e0f14250..45da42b1 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java @@ -60,9 +60,9 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re color TEXT, expiration_time INTEGER NOT NULL DEFAULT 0, - blocked BOOLEAN NOT NULL DEFAULT FALSE, - archived BOOLEAN NOT NULL DEFAULT FALSE, - profile_sharing BOOLEAN NOT NULL DEFAULT FALSE, + blocked INTEGER NOT NULL DEFAULT FALSE, + archived INTEGER NOT NULL DEFAULT FALSE, + profile_sharing INTEGER NOT NULL DEFAULT FALSE, profile_last_update_timestamp INTEGER NOT NULL DEFAULT 0, profile_given_name TEXT, @@ -73,7 +73,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re profile_mobile_coin_address BLOB, profile_unidentified_access_mode TEXT, profile_capabilities TEXT - ); + ) STRICT; """); } } @@ -711,7 +711,8 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re final var profileKeyCredential = getExpiringProfileKeyCredential(connection, recipientId); if (profileKeyCredential == null) { - final var toBeMergedProfileKeyCredential = getExpiringProfileKeyCredential(connection, toBeMergedRecipientId); + final var toBeMergedProfileKeyCredential = getExpiringProfileKeyCredential(connection, + toBeMergedRecipientId); storeExpiringProfileKeyCredential(connection, recipientId, toBeMergedProfileKeyCredential); } diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/sendLog/MessageSendLogStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/sendLog/MessageSendLogStore.java index c7e6cdb1..d0034d1b 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/sendLog/MessageSendLogStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/sendLog/MessageSendLogStore.java @@ -73,8 +73,8 @@ public class MessageSendLogStore implements AutoCloseable { timestamp INTEGER NOT NULL, content BLOB NOT NULL, content_hint INTEGER NOT NULL, - urgent BOOLEAN NOT NULL - ); + urgent INTEGER NOT NULL + ) STRICT; CREATE INDEX mslc_timestamp_index ON message_send_log_content (timestamp); CREATE INDEX msl_recipient_index ON message_send_log (uuid, device_id, content_id); CREATE INDEX msl_content_index ON message_send_log (content_id); diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/stickers/StickerStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/stickers/StickerStore.java index aeed8ccd..6667d978 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/stickers/StickerStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/stickers/StickerStore.java @@ -26,8 +26,8 @@ public class StickerStore { _id INTEGER PRIMARY KEY, pack_id BLOB UNIQUE NOT NULL, pack_key BLOB NOT NULL, - installed BOOLEAN NOT NULL DEFAULT FALSE - ); + installed INTEGER NOT NULL DEFAULT FALSE + ) STRICT; """); } }