1 package org
.asamk
.signal
.manager
.storage
;
3 import com
.zaxxer
.hikari
.HikariDataSource
;
5 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientStore
;
6 import org
.asamk
.signal
.manager
.storage
.sendLog
.MessageSendLogStore
;
7 import org
.asamk
.signal
.manager
.storage
.stickers
.StickerStore
;
8 import org
.slf4j
.Logger
;
9 import org
.slf4j
.LoggerFactory
;
12 import java
.sql
.Connection
;
13 import java
.sql
.SQLException
;
15 public class AccountDatabase
extends Database
{
17 private final static Logger logger
= LoggerFactory
.getLogger(AccountDatabase
.class);
18 private static final long DATABASE_VERSION
= 3;
20 private AccountDatabase(final HikariDataSource dataSource
) {
21 super(logger
, DATABASE_VERSION
, dataSource
);
24 public static AccountDatabase
init(File databaseFile
) throws SQLException
{
25 return initDatabase(databaseFile
, AccountDatabase
::new);
29 protected void createDatabase(final Connection connection
) throws SQLException
{
30 RecipientStore
.createSql(connection
);
31 MessageSendLogStore
.createSql(connection
);
32 StickerStore
.createSql(connection
);
36 protected void upgradeDatabase(final Connection connection
, final long oldVersion
) throws SQLException
{
38 logger
.debug("Updating database: Creating recipient table");
39 try (final var statement
= connection
.createStatement()) {
40 statement
.executeUpdate("""
41 CREATE TABLE recipient (
42 _id INTEGER PRIMARY KEY AUTOINCREMENT,
46 profile_key_credential BLOB,
52 expiration_time INTEGER NOT NULL DEFAULT 0,
53 blocked BOOLEAN NOT NULL DEFAULT FALSE,
54 archived BOOLEAN NOT NULL DEFAULT FALSE,
55 profile_sharing BOOLEAN NOT NULL DEFAULT FALSE,
57 profile_last_update_timestamp INTEGER NOT NULL DEFAULT 0,
58 profile_given_name TEXT,
59 profile_family_name TEXT,
61 profile_about_emoji TEXT,
62 profile_avatar_url_path TEXT,
63 profile_mobile_coin_address BLOB,
64 profile_unidentified_access_mode TEXT,
65 profile_capabilities TEXT
71 logger
.debug("Updating database: Creating sticker table");
72 try (final var statement
= connection
.createStatement()) {
73 statement
.executeUpdate("""
74 CREATE TABLE sticker (
75 _id INTEGER PRIMARY KEY,
76 pack_id BLOB UNIQUE NOT NULL,
77 pack_key BLOB NOT NULL,
78 installed BOOLEAN NOT NULL DEFAULT FALSE