1 package org
.asamk
.signal
.manager
.storage
;
3 import com
.zaxxer
.hikari
.HikariDataSource
;
5 import org
.asamk
.signal
.manager
.storage
.prekeys
.PreKeyStore
;
6 import org
.asamk
.signal
.manager
.storage
.prekeys
.SignedPreKeyStore
;
7 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientStore
;
8 import org
.asamk
.signal
.manager
.storage
.sendLog
.MessageSendLogStore
;
9 import org
.asamk
.signal
.manager
.storage
.stickers
.StickerStore
;
10 import org
.slf4j
.Logger
;
11 import org
.slf4j
.LoggerFactory
;
14 import java
.sql
.Connection
;
15 import java
.sql
.SQLException
;
17 public class AccountDatabase
extends Database
{
19 private final static Logger logger
= LoggerFactory
.getLogger(AccountDatabase
.class);
20 private static final long DATABASE_VERSION
= 4;
22 private AccountDatabase(final HikariDataSource dataSource
) {
23 super(logger
, DATABASE_VERSION
, dataSource
);
26 public static AccountDatabase
init(File databaseFile
) throws SQLException
{
27 return initDatabase(databaseFile
, AccountDatabase
::new);
31 protected void createDatabase(final Connection connection
) throws SQLException
{
32 RecipientStore
.createSql(connection
);
33 MessageSendLogStore
.createSql(connection
);
34 StickerStore
.createSql(connection
);
35 PreKeyStore
.createSql(connection
);
36 SignedPreKeyStore
.createSql(connection
);
40 protected void upgradeDatabase(final Connection connection
, final long oldVersion
) throws SQLException
{
42 logger
.debug("Updating database: Creating recipient table");
43 try (final var statement
= connection
.createStatement()) {
44 statement
.executeUpdate("""
45 CREATE TABLE recipient (
46 _id INTEGER PRIMARY KEY AUTOINCREMENT,
50 profile_key_credential BLOB,
56 expiration_time INTEGER NOT NULL DEFAULT 0,
57 blocked BOOLEAN NOT NULL DEFAULT FALSE,
58 archived BOOLEAN NOT NULL DEFAULT FALSE,
59 profile_sharing BOOLEAN NOT NULL DEFAULT FALSE,
61 profile_last_update_timestamp INTEGER NOT NULL DEFAULT 0,
62 profile_given_name TEXT,
63 profile_family_name TEXT,
65 profile_about_emoji TEXT,
66 profile_avatar_url_path TEXT,
67 profile_mobile_coin_address BLOB,
68 profile_unidentified_access_mode TEXT,
69 profile_capabilities TEXT
75 logger
.debug("Updating database: Creating sticker table");
76 try (final var statement
= connection
.createStatement()) {
77 statement
.executeUpdate("""
78 CREATE TABLE sticker (
79 _id INTEGER PRIMARY KEY,
80 pack_id BLOB UNIQUE NOT NULL,
81 pack_key BLOB NOT NULL,
82 installed BOOLEAN NOT NULL DEFAULT FALSE
88 logger
.debug("Updating database: Creating pre key tables");
89 try (final var statement
= connection
.createStatement()) {
90 statement
.executeUpdate("""
91 CREATE TABLE signed_pre_key (
92 _id INTEGER PRIMARY KEY,
93 account_id_type INTEGER NOT NULL,
94 key_id INTEGER NOT NULL,
95 public_key BLOB NOT NULL,
96 private_key BLOB NOT NULL,
97 signature BLOB NOT NULL,
98 timestamp INTEGER DEFAULT 0,
99 UNIQUE(account_id_type, key_id)
101 CREATE TABLE pre_key (
102 _id INTEGER PRIMARY KEY,
103 account_id_type INTEGER NOT NULL,
104 key_id INTEGER NOT NULL,
105 public_key BLOB NOT NULL,
106 private_key BLOB NOT NULL,
107 UNIQUE(account_id_type, key_id)