]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/storage/AccountDatabase.java
9c504b4731776e441c537eabdc2f4e43ec211b1d
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / storage / AccountDatabase.java
1 package org.asamk.signal.manager.storage;
2
3 import com.zaxxer.hikari.HikariDataSource;
4
5 import org.asamk.signal.manager.storage.recipients.RecipientStore;
6 import org.asamk.signal.manager.storage.sendLog.MessageSendLogStore;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import java.io.File;
11 import java.sql.Connection;
12 import java.sql.SQLException;
13
14 public class AccountDatabase extends Database {
15
16 private final static Logger logger = LoggerFactory.getLogger(AccountDatabase.class);
17 private static final long DATABASE_VERSION = 2;
18
19 private AccountDatabase(final HikariDataSource dataSource) {
20 super(logger, DATABASE_VERSION, dataSource);
21 }
22
23 public static AccountDatabase init(File databaseFile) throws SQLException {
24 return initDatabase(databaseFile, AccountDatabase::new);
25 }
26
27 @Override
28 protected void createDatabase(final Connection connection) throws SQLException {
29 RecipientStore.createSql(connection);
30 MessageSendLogStore.createSql(connection);
31 }
32
33 @Override
34 protected void upgradeDatabase(final Connection connection, final long oldVersion) throws SQLException {
35 if (oldVersion < 2) {
36 logger.debug("Updating database: Creating recipient table");
37 try (final var statement = connection.createStatement()) {
38 statement.executeUpdate("""
39 CREATE TABLE recipient (
40 _id INTEGER PRIMARY KEY AUTOINCREMENT,
41 number TEXT UNIQUE,
42 uuid BLOB UNIQUE,
43 profile_key BLOB,
44 profile_key_credential BLOB,
45
46 given_name TEXT,
47 family_name TEXT,
48 color TEXT,
49
50 expiration_time INTEGER NOT NULL DEFAULT 0,
51 blocked BOOLEAN NOT NULL DEFAULT FALSE,
52 archived BOOLEAN NOT NULL DEFAULT FALSE,
53 profile_sharing BOOLEAN NOT NULL DEFAULT FALSE,
54
55 profile_last_update_timestamp INTEGER NOT NULL DEFAULT 0,
56 profile_given_name TEXT,
57 profile_family_name TEXT,
58 profile_about TEXT,
59 profile_about_emoji TEXT,
60 profile_avatar_url_path TEXT,
61 profile_mobile_coin_address BLOB,
62 profile_unidentified_access_mode TEXT,
63 profile_capabilities TEXT
64 );
65 """);
66 }
67 }
68 }
69 }