Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: postgres configuration in jvm for global db (do not merge) (WPB-9012) #2758

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
<ID>ArgumentListWrapping:GetPaginatedFlowOfMessagesBySearchQueryAndConversationIdUseCase.kt$GetPaginatedFlowOfMessagesBySearchQueryAndConversationIdUseCase$( searchQuery, conversationId, pagingConfig, startingOffset )</ID>
<ID>ArgumentListWrapping:GetSessionsUseCase.kt$GetSessionsUseCase$( { when (it) { StorageFailure.DataNotFound -> GetAllSessionsResult.Failure.NoSessionFound is StorageFailure.Generic -> GetAllSessionsResult.Failure.Generic(it) } }, { GetAllSessionsResult.Success(it) } )</ID>
<ID>ArgumentListWrapping:GetUserInfoUseCase.kt$GetUserInfoUseCaseImpl$( { GetUserInfoResult.Failure }, { team -> GetUserInfoResult.Success(otherUser, team) })</ID>
<ID>ArgumentListWrapping:GlobalDBBaseTest.kt$GlobalDBBaseTest$( PlatformDatabaseData(StorageData.FileBacked(storePath)), StandardTestDispatcher(), null, false )</ID>
<ID>ArgumentListWrapping:GlobalDatabase.kt$( identifier = Int.MIN_VALUE, sql = """SELECT table_name FROM information_schema.tables where table_name = 'accounts'""", mapper = { if (it.next().value) { val result = it.getString(0) println("THE RESULT: $result") app.cash.sqldelight.db.QueryResult.Value(result?.isNotEmpty()) } else { app.cash.sqldelight.db.QueryResult.Value(false) } }, parameters = 0 )</ID>
Comment on lines +131 to +132
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a draft, but are new lines to baseline.xml intended?

<ID>ArgumentListWrapping:GuestRoomConfigHandler.kt$GuestRoomConfigHandler$( { false }, { it.isGuestRoomLinkEnabled != status } )</ID>
<ID>ArgumentListWrapping:HandleExternalRequestAction.kt$( """ Hey there, I hope you're doing well. I've got a bit of a craving for bananas, and I was wondering if you might be able to share a few with me? It would mean a lot. 😊 Thanks a bunch, A friendly monkey 🍌🐵 """.trimIndent(), """ Yo, I'm in need of some bananas, my friend. Can you hook me up? I'd appreciate it big time. Respect, A neutral monkey 🍌 """.trimIndent(), """ Listen up, I ain't messin' around. I want them bananas, and I want 'em now. You better deliver or there'll be consequences. No games, An evil monkey 🍌👿💀 """.trimIndent() )</ID>
<ID>ArgumentListWrapping:InstanceService.kt$InstanceService$( instanceRequest.email, instanceRequest.password, true, secondFactorVerificationCode = instanceRequest.verificationCode )</ID>
Expand Down Expand Up @@ -307,6 +309,7 @@
<ID>CommentSpacing:UserDAOTest.kt$UserDAOTest$//given</ID>
<ID>EmptyFunctionBlock:FileTestHelper.kt$FileTestHelper${ }</ID>
<ID>EmptyKtFile:FetchApiVersionUseCaseTest.kt$.FetchApiVersionUseCaseTest.kt</ID>
<ID>Filename:BooleanExt.kt$com.wire.kalium.persistence.dao.BooleanExt.kt</ID>
<ID>Filename:ConversationStatus.kt$com.wire.kalium.logic.data.conversation.ConversationStatus.kt</ID>
<ID>Filename:FileUtilTest.kt$com.wire.kalium.util.FileUtilTest.kt</ID>
<ID>Filename:GetOtherUserClientsUseCaseTest.kt$com.wire.kalium.logic.feature.client.GetOtherUserClientsUseCaseTest.kt</ID>
Expand Down Expand Up @@ -401,6 +404,7 @@
<ID>LongParameterList:ToggleReactionUseCase.kt$ToggleReactionUseCase$( clientId: ClientId, conversationId: ConversationId, date: String, messageId: String, removedReaction: String, currentReactions: UserReactions )</ID>
<ID>MagicNumber:ConversationStatus.kt$MutedConversationStatus.AllMuted$3</ID>
<ID>MagicNumber:GlobalCallManager.kt$LogHandlerImpl$3</ID>
<ID>MagicNumber:GlobalDatabase.kt$3</ID>
<ID>MagicNumber:NetworkUtils.kt$300</ID>
<ID>MagicNumber:NetworkUtils.kt$399</ID>
<ID>MagicNumber:NetworkUtils.kt$400</ID>
Expand All @@ -411,10 +415,6 @@
<ID>MatchingDeclarationName:ConversationStatus.kt$MutedConversationStatus</ID>
<ID>MatchingDeclarationName:CryptoboxCRUDStore.module_@wireapp_cryptobox.kt$CryptoboxCRUDStore : PreKeyStore</ID>
<ID>MatchingDeclarationName:CryptoboxSession.module_@wireapp_cryptobox.kt$CryptoboxSession</ID>
<ID>MatchingDeclarationName:DriverBuilder.android.kt$DriverBuilder</ID>
<ID>MatchingDeclarationName:DriverBuilder.apple.kt$DriverBuilder</ID>
<ID>MatchingDeclarationName:DriverBuilder.js.kt$DriverBuilder</ID>
<ID>MatchingDeclarationName:DriverBuilder.jvm.kt$DriverBuilder</ID>
<ID>MatchingDeclarationName:Encoder.module_@wireapp_cbor.kt$Encoder</ID>
<ID>MatchingDeclarationName:FileUtilTest.kt$FileTestHelper</ID>
<ID>MatchingDeclarationName:GetOtherUserClientsUseCaseTest.kt$ObserveClientsByUserIdUseCaseTest</ID>
Expand Down Expand Up @@ -939,7 +939,7 @@
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(libs.apacheTika) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(libs.coroutines.core) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(libs.ktor.okHttp) implementation(libs.okhttp.loggingInterceptor) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(libs.sqldelight.jvmDriver) implementation(libs.sqlite.xerialDriver) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(libs.sqldelight.jvmDriver) implementation(libs.sqldelight.jdbcDriver) implementation(libs.sqlite.xerialDriver) implementation(libs.hikaricp) implementation(libs.postgres.driver) implementation(libs.testContainers.postgres) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmMain by getting { dependencies { implementation(project(":logic")) implementation(project(":calling")) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmTest by getting</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val jvmTest by getting { dependencies { implementation(libs.konsist) } }</ID>
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ sqldelight-androidxPaging = { module = "app.cash.sqldelight:androidx-paging3-ext
sqldelight-nativeDriver = { module = "app.cash.sqldelight:native-driver", version.ref = "sqldelight" }
sqldelight-jvmDriver = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
sqldelight-jsDriver = { module = "app.cash.sqldelight:web-worker-driver", version.ref = "sqldelight" }
sqldelight-jdbcDriver = { module = "app.cash.sqldelight:jdbc-driver", version.ref = "sqldelight" }
sqldelight-primitiveAdapters = { module = "app.cash.sqldelight:primitive-adapters", version.ref = "sqldelight" }
sqldelight-dialect = { module = "app.cash.sqldelight:sqlite-3-38-dialect", version.ref = "sqldelight" }
sqldelight-postgres = { module = "app.cash.sqldelight:postgresql-dialect", version.ref = "sqldelight" }
Expand All @@ -189,13 +190,16 @@ sqldelight-async = { module = "app.cash.sqldelight:async-extensions", version.re
r2dbc-postgres = { module = "org.postgresql:r2dbc-postgresql", version.ref = "postgres" }
r2dbc-spi = { module = "io.r2dbc:r2dbc-spi", version.ref = "r2dbc" }
sqlite-xerialDriver = { module = "org.xerial:sqlite-jdbc", version.ref = "xerialDriver" }
hikaricp = { module = "com.zaxxer:HikariCP", version = "5.0.1" }
postgres-driver = { module = "org.postgresql:postgresql", version = "42.5.4" }

# mocks and testing
mockative-runtime = { module = "io.mockative:mockative", version.ref = "mockative" }
mockative-processor = { module = "io.mockative:mockative-processor", version.ref = "mockative" }
turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
konsist = { module = "com.lemonappdev:konsist", version.ref = "konsist" }
testContainers-postgres = { module = "org.testcontainers:postgresql", version = "1.19.6" }

# detekt
detekt-cli = { module = "io.gitlab.arturbosch.detekt:detekt-cli", version.ref = "detekt" }
Expand Down
4 changes: 4 additions & 0 deletions persistence/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ kotlin {
val jvmMain by getting {
dependencies {
implementation(libs.sqldelight.jvmDriver)
implementation(libs.sqldelight.jdbcDriver)
implementation(libs.sqlite.xerialDriver)
implementation(libs.hikaricp)
implementation(libs.postgres.driver)
implementation(libs.testContainers.postgres)
}
}
val jvmTest by getting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ actual abstract class GlobalDBBaseTest {
context.deleteDatabase(FileNameUtil.globalDBName())
}

actual fun createDatabase(): GlobalDatabaseBuilder = globalDatabaseProvider(
actual fun createDatabase(platformDatabaseData: PlatformDatabaseData): GlobalDatabaseBuilder = globalDatabaseProvider(
platformDatabaseData = PlatformDatabaseData(ApplicationProvider.getApplicationContext()),
queriesContext = KaliumDispatcherImpl.unconfined,
passphrase = GlobalDatabaseSecret("test_db_secret".toByteArray()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
package com.wire.kalium.persistence

import com.wire.kalium.persistence.db.GlobalDatabaseBuilder
import com.wire.kalium.persistence.db.PlatformDatabaseData

actual abstract class GlobalDBBaseTest {
actual fun deleteDatabase() {
TODO("Not yet implemented")
}

actual fun createDatabase(): GlobalDatabaseBuilder {
actual fun createDatabase(platformDatabaseData: PlatformDatabaseData): GlobalDatabaseBuilder {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ actual abstract class GlobalDBBaseTest {
deleteDatabase(FileNameUtil.globalDBName(), storePath)
}

actual fun createDatabase(): GlobalDatabaseBuilder {
actual fun createDatabase(platformDatabaseData: PlatformDatabaseData): GlobalDatabaseBuilder {
return globalDatabaseProvider(
PlatformDatabaseData(StorageData.FileBacked(storePath)), StandardTestDispatcher(), null, false
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import com.wire.kalium.persistence.dao.ManagedByEntity;
import com.wire.kalium.persistence.dao.QualifiedIDEntity;
import com.wire.kalium.persistence.model.LogoutReason;
import com.wire.kalium.persistence.dao.BooleanEntity;
import kotlin.Boolean;
import kotlin.Int;

CREATE TABLE Accounts (
id TEXT AS QualifiedIDEntity PRIMARY KEY NOT NULL,
Expand All @@ -10,12 +12,12 @@ CREATE TABLE Accounts (
tenant TEXT,
server_config_id TEXT NOT NULL,
logout_reason TEXT AS LogoutReason,
isPersistentWebSocketEnabled INTEGER AS Boolean NOT NULL DEFAULT 0,
isPersistentWebSocketEnabled INTEGER AS BooleanEntity NOT NULL DEFAULT 0,
managed_by TEXT AS ManagedByEntity
);

insertOrReplace:
INSERT OR REPLACE INTO Accounts (id, scim_external_id, subject, tenant, server_config_id, logout_reason, isPersistentWebSocketEnabled)
INSERT INTO Accounts (id, scim_external_id, subject, tenant, server_config_id, logout_reason, isPersistentWebSocketEnabled)
VALUES (:id, :scimExternalId, :subject, :tenant, :serverConfigId, :logoutReason,:isPersistentWebSocketEnabled);

delete:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE CurrentAccount (
);

update:
INSERT OR REPLACE INTO CurrentAccount (id, user_id) VALUES (1, :user_id);
INSERT INTO CurrentAccount (id, user_id) VALUES (1, :user_id);

currentAccountInfo:
SELECT id, logout_reason FROM Accounts WHERE id = (SELECT user_id FROM CurrentAccount WHERE id = 1);
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@

enableForeignKeyContraints:
PRAGMA foreign_keys = 1;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import kotlin.Boolean;
import kotlin.Int;
import com.wire.kalium.persistence.dao.BooleanEntity;

CREATE TABLE ServerConfiguration (
id TEXT PRIMARY KEY NOT NULL,
Expand All @@ -10,12 +11,12 @@ CREATE TABLE ServerConfiguration (
blackListUrl TEXT NOT NULL,
teamsUrl TEXT NOT NULL,
websiteUrl TEXT NOT NULL,
isOnPremises INTEGER AS Boolean NOT NULL,
isOnPremises INTEGER AS BooleanEntity NOT NULL,
domain TEXT,
commonApiVersion INTEGER AS Int NOT NULL,
federation INTEGER AS Boolean NOT NULL,
federation INTEGER AS BooleanEntity NOT NULL,
apiProxyHost TEXT,
apiProxyNeedsAuthentication INTEGER AS Boolean,
apiProxyNeedsAuthentication INTEGER AS BooleanEntity,
apiProxyPort INTEGER AS Int,
lastBlackListCheck TEXT,
CONSTRAINT server_config_unique UNIQUE (title, apiBaseUrl, webSocketBaseUrl, domain, apiProxyHost, apiProxyPort)
Expand All @@ -25,7 +26,7 @@ deleteById:
DELETE FROM ServerConfiguration WHERE id = ?;

insert:
INSERT OR FAIL INTO ServerConfiguration(id, apiBaseUrl, accountBaseUrl, webSocketBaseUrl, blackListUrl, teamsUrl, websiteUrl, title, isOnPremises, federation, domain, commonApiVersion, apiProxyHost, apiProxyNeedsAuthentication, apiProxyPort)
INSERT INTO ServerConfiguration(id, apiBaseUrl, accountBaseUrl, webSocketBaseUrl, blackListUrl, teamsUrl, websiteUrl, title, isOnPremises, federation, domain, commonApiVersion, apiProxyHost, apiProxyNeedsAuthentication, apiProxyPort)
VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?);

updateApiVersion:
Expand Down
4 changes: 2 additions & 2 deletions persistence/src/commonMain/db_global/migrations/3.sqm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import kotlin.Boolean;
import com.wire.kalium.persistence.dao.BooleanEntity;

ALTER TABLE Accounts
ADD COLUMN isPersistentWebSocketEnabled INTEGER AS Boolean NOT NULL DEFAULT(0);
ADD COLUMN isPersistentWebSocketEnabled INTEGER AS BooleanEntity NOT NULL DEFAULT(0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.persistence.adapter

import app.cash.sqldelight.ColumnAdapter
import com.wire.kalium.persistence.dao.BooleanEntity

internal object CrossCompatBooleanAdapter : ColumnAdapter<BooleanEntity, Long?> {
override fun decode(databaseValue: Long?): BooleanEntity {
return databaseValue == 1L
}

override fun encode(value: BooleanEntity): Long {
return value.toLong()
}
}

fun Boolean.toLong(): Long {
return when (this) {
true -> 1
false -> 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.persistence.dao

typealias BooleanEntity = Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

package com.wire.kalium.persistence.db

import app.cash.sqldelight.ColumnAdapter
import app.cash.sqldelight.EnumColumnAdapter
import app.cash.sqldelight.adapter.primitive.IntColumnAdapter
import app.cash.sqldelight.db.SqlDriver
import com.wire.kalium.persistence.Accounts
import com.wire.kalium.persistence.CurrentAccount
import com.wire.kalium.persistence.GlobalDatabase
import com.wire.kalium.persistence.ServerConfiguration
import com.wire.kalium.persistence.adapter.CrossCompatBooleanAdapter
import com.wire.kalium.persistence.adapter.LogoutReasonAdapter
import com.wire.kalium.persistence.adapter.QualifiedIDAdapter
import com.wire.kalium.persistence.dao.BooleanEntity
import com.wire.kalium.persistence.daokaliumdb.AccountsDAO
import com.wire.kalium.persistence.daokaliumdb.AccountsDAOImpl
import com.wire.kalium.persistence.daokaliumdb.ServerConfigurationDAO
Expand All @@ -49,20 +52,24 @@ class GlobalDatabaseBuilder internal constructor(
sqlDriver,
ServerConfigurationAdapter = ServerConfiguration.Adapter(
commonApiVersionAdapter = IntColumnAdapter,
apiProxyPortAdapter = IntColumnAdapter
isOnPremisesAdapter = CrossCompatBooleanAdapter as ColumnAdapter<BooleanEntity, Long>,
apiProxyPortAdapter = IntColumnAdapter,
federationAdapter = CrossCompatBooleanAdapter as ColumnAdapter<BooleanEntity, Long>,
apiProxyNeedsAuthenticationAdapter = CrossCompatBooleanAdapter as ColumnAdapter<BooleanEntity, Long>
),
AccountsAdapter = Accounts.Adapter(
idAdapter = QualifiedIDAdapter,
logout_reasonAdapter = LogoutReasonAdapter,
managed_byAdapter = EnumColumnAdapter()
managed_byAdapter = EnumColumnAdapter(),
isPersistentWebSocketEnabledAdapter = CrossCompatBooleanAdapter as ColumnAdapter<BooleanEntity, Long>
),
CurrentAccountAdapter = CurrentAccount.Adapter(
user_idAdapter = QualifiedIDAdapter
)
)

init {
database.globalDatabasePropertiesQueries.enableForeignKeyContraints()
// database.globalDatabasePropertiesQueries.enableForeignKeyContraints()
}

val serverConfigurationDAO: ServerConfigurationDAO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
package com.wire.kalium.persistence

import com.wire.kalium.persistence.db.GlobalDatabaseBuilder
import com.wire.kalium.persistence.db.PlatformDatabaseData

expect abstract class GlobalDBBaseTest() {
fun deleteDatabase()
fun createDatabase(): GlobalDatabaseBuilder
fun createDatabase(platformDatabaseData: PlatformDatabaseData): GlobalDatabaseBuilder
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
package com.wire.kalium.persistence

import com.wire.kalium.persistence.db.GlobalDatabaseBuilder
import com.wire.kalium.persistence.db.PlatformDatabaseData

actual abstract class GlobalDBBaseTest {
actual fun deleteDatabase() {
TODO("Not yet implemented")
}

actual fun createDatabase(): GlobalDatabaseBuilder {
actual fun createDatabase(platformDatabaseData: PlatformDatabaseData): GlobalDatabaseBuilder {
TODO("Not yet implemented")
}
}
Loading
Loading