diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -308,6 +308,88 @@ return false; } +bool create_schema(sqlite3 *db) { + char *error; + sqlite3_exec( + db, + "CREATE TABLE IF NOT EXISTS drafts (" + " key TEXT UNIQUE PRIMARY KEY NOT NULL," + " text TEXT NOT NULL" + ");" + + "CREATE TABLE IF NOT EXISTS messages (" + " id TEXT UNIQUE PRIMARY KEY NOT NULL," + " local_id TEXT," + " thread TEXT NOT NULL," + " user TEXT NOT NULL," + " type INTEGER NOT NULL," + " future_type INTEGER," + " content TEXT," + " time INTEGER NOT NULL" + ");" + + "CREATE TABLE IF NOT EXISTS olm_persist_account (" + " id INTEGER UNIQUE PRIMARY KEY NOT NULL," + " account_data TEXT NOT NULL" + ");" + + "CREATE TABLE IF NOT EXISTS olm_persist_sessions (" + " target_user_id TEXT UNIQUE PRIMARY KEY NOT NULL," + " session_data TEXT NOT NULL" + ");" + + "CREATE TABLE IF NOT EXISTS media (" + " id TEXT UNIQUE PRIMARY KEY NOT NULL," + " container TEXT NOT NULL," + " thread TEXT NOT NULL," + " uri TEXT NOT NULL," + " type TEXT NOT NULL," + " extras TEXT NOT NULL" + ");" + + "CREATE TABLE IF NOT EXISTS threads (" + " id TEXT UNIQUE PRIMARY KEY NOT NULL," + " type INTEGER NOT NULL," + " name TEXT," + " description TEXT," + " color TEXT NOT NULL," + " creation_time BIGINT NOT NULL," + " parent_thread_id TEXT," + " containing_thread_id TEXT," + " community TEXT," + " members TEXT NOT NULL," + " roles TEXT NOT NULL," + " current_user TEXT NOT NULL," + " source_message_id TEXT," + " replies_count INTEGER NOT NULL" + ");" + + "CREATE TABLE IF NOT EXISTS metadata (" + " name TEXT UNIQUE PRIMARY KEY NOT NULL," + " data TEXT NOT NULL" + ");" + + "CREATE INDEX IF NOT EXISTS media_idx_container" + " ON media (container);" + + "CREATE INDEX IF NOT EXISTS messages_idx_thread_time" + " ON messages (thread, time);", + nullptr, + nullptr, + &error); + + if (!error) { + return true; + } + + std::ostringstream stringStream; + stringStream << "Error creating tables: " << error; + Logger::log(stringStream.str()); + + sqlite3_free(error); + return false; +} + void set_encryption_key(sqlite3 *db) { std::string set_encryption_key_query = "PRAGMA key = \"x'" + SQLiteQueryExecutor::encryptionKey + "'\";";