Skip to content

Commit c759137

Browse files
feat(core:database): Migrate database module to KMP (#2752)
Co-authored-by: Sk Niyaj Ali <[email protected]>
1 parent c67f9d4 commit c759137

File tree

46 files changed

+810
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+810
-183
lines changed

androidApp/dependencies/demoDebugRuntimeClasspath.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
113113
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
114114
androidx.profileinstaller:profileinstaller:1.4.1
115115
androidx.resourceinspection:resourceinspection-annotation:1.0.1
116-
androidx.room:room-common:2.6.1
117-
androidx.room:room-ktx:2.6.1
118-
androidx.room:room-runtime:2.6.1
116+
androidx.room:room-common-jvm:2.7.0-alpha12
117+
androidx.room:room-common:2.7.0-alpha12
118+
androidx.room:room-ktx:2.7.0-alpha12
119+
androidx.room:room-runtime-android:2.7.0-alpha12
120+
androidx.room:room-runtime:2.7.0-alpha12
119121
androidx.savedstate:savedstate-ktx:1.2.1
120122
androidx.savedstate:savedstate:1.2.1
121-
androidx.sqlite:sqlite-framework:2.4.0
122-
androidx.sqlite:sqlite:2.4.0
123+
androidx.sqlite:sqlite-android:2.5.0-alpha12
124+
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
125+
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
126+
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
127+
androidx.sqlite:sqlite-framework:2.5.0-alpha12
128+
androidx.sqlite:sqlite:2.5.0-alpha12
123129
androidx.startup:startup-runtime:1.1.1
124130
androidx.tracing:tracing-ktx:1.2.0
125131
androidx.tracing:tracing:1.2.0

androidApp/dependencies/demoReleaseRuntimeClasspath.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
108108
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
109109
androidx.profileinstaller:profileinstaller:1.4.1
110110
androidx.resourceinspection:resourceinspection-annotation:1.0.1
111-
androidx.room:room-common:2.6.1
112-
androidx.room:room-ktx:2.6.1
113-
androidx.room:room-runtime:2.6.1
111+
androidx.room:room-common-jvm:2.7.0-alpha12
112+
androidx.room:room-common:2.7.0-alpha12
113+
androidx.room:room-ktx:2.7.0-alpha12
114+
androidx.room:room-runtime-android:2.7.0-alpha12
115+
androidx.room:room-runtime:2.7.0-alpha12
114116
androidx.savedstate:savedstate-ktx:1.2.1
115117
androidx.savedstate:savedstate:1.2.1
116-
androidx.sqlite:sqlite-framework:2.4.0
117-
androidx.sqlite:sqlite:2.4.0
118+
androidx.sqlite:sqlite-android:2.5.0-alpha12
119+
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
120+
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
121+
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
122+
androidx.sqlite:sqlite-framework:2.5.0-alpha12
123+
androidx.sqlite:sqlite:2.5.0-alpha12
118124
androidx.startup:startup-runtime:1.1.1
119125
androidx.tracing:tracing-ktx:1.2.0
120126
androidx.tracing:tracing:1.2.0

androidApp/dependencies/prodDebugRuntimeClasspath.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
113113
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
114114
androidx.profileinstaller:profileinstaller:1.4.1
115115
androidx.resourceinspection:resourceinspection-annotation:1.0.1
116-
androidx.room:room-common:2.6.1
117-
androidx.room:room-ktx:2.6.1
118-
androidx.room:room-runtime:2.6.1
116+
androidx.room:room-common-jvm:2.7.0-alpha12
117+
androidx.room:room-common:2.7.0-alpha12
118+
androidx.room:room-ktx:2.7.0-alpha12
119+
androidx.room:room-runtime-android:2.7.0-alpha12
120+
androidx.room:room-runtime:2.7.0-alpha12
119121
androidx.savedstate:savedstate-ktx:1.2.1
120122
androidx.savedstate:savedstate:1.2.1
121-
androidx.sqlite:sqlite-framework:2.4.0
122-
androidx.sqlite:sqlite:2.4.0
123+
androidx.sqlite:sqlite-android:2.5.0-alpha12
124+
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
125+
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
126+
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
127+
androidx.sqlite:sqlite-framework:2.5.0-alpha12
128+
androidx.sqlite:sqlite:2.5.0-alpha12
123129
androidx.startup:startup-runtime:1.1.1
124130
androidx.tracing:tracing-ktx:1.2.0
125131
androidx.tracing:tracing:1.2.0

androidApp/dependencies/prodReleaseRuntimeClasspath.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
108108
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
109109
androidx.profileinstaller:profileinstaller:1.4.1
110110
androidx.resourceinspection:resourceinspection-annotation:1.0.1
111-
androidx.room:room-common:2.6.1
112-
androidx.room:room-ktx:2.6.1
113-
androidx.room:room-runtime:2.6.1
111+
androidx.room:room-common-jvm:2.7.0-alpha12
112+
androidx.room:room-common:2.7.0-alpha12
113+
androidx.room:room-ktx:2.7.0-alpha12
114+
androidx.room:room-runtime-android:2.7.0-alpha12
115+
androidx.room:room-runtime:2.7.0-alpha12
114116
androidx.savedstate:savedstate-ktx:1.2.1
115117
androidx.savedstate:savedstate:1.2.1
116-
androidx.sqlite:sqlite-framework:2.4.0
117-
androidx.sqlite:sqlite:2.4.0
118+
androidx.sqlite:sqlite-android:2.5.0-alpha12
119+
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
120+
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
121+
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
122+
androidx.sqlite:sqlite-framework:2.5.0-alpha12
123+
androidx.sqlite:sqlite:2.5.0-alpha12
118124
androidx.startup:startup-runtime:1.1.1
119125
androidx.tracing:tracing-ktx:1.2.0
120126
androidx.tracing:tracing:1.2.0

build-logic/convention/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ gradlePlugin {
7575
id = "mifos.android.hilt"
7676
implementationClass = "AndroidHiltConventionPlugin"
7777
}
78-
register("androidRoom") {
79-
id = "mifos.android.room"
80-
implementationClass = "AndroidRoomConventionPlugin"
78+
register("kmpRoom") {
79+
id = "mifos.kmp.room"
80+
implementationClass = "KMPRoomConventionPlugin"
8181
}
8282

8383
// Utility Plugins

build-logic/convention/src/main/kotlin/AndroidRoomConventionPlugin.kt renamed to build-logic/convention/src/main/kotlin/KMPRoomConventionPlugin.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.gradle.kotlin.dsl.configure
66
import org.gradle.kotlin.dsl.dependencies
77
import org.mifos.mobile.libs
88

9-
class AndroidRoomConventionPlugin : Plugin<Project> {
9+
class KMPRoomConventionPlugin : Plugin<Project> {
1010
override fun apply(target: Project) {
1111
with(target) {
1212
pluginManager.apply("androidx.room")
@@ -26,7 +26,17 @@ class AndroidRoomConventionPlugin : Plugin<Project> {
2626
dependencies {
2727
"implementation"(libs.findLibrary("androidx.room.runtime").get())
2828
"implementation"(libs.findLibrary("androidx.room.ktx").get())
29-
"ksp"(libs.findLibrary("androidx.room.compiler").get())
29+
// Adding ksp dependencies for multiple platforms
30+
listOf(
31+
"kspDesktop",
32+
"kspAndroid",
33+
"kspIosArm64",
34+
"kspIosX64",
35+
"kspIosSimulatorArm64",
36+
// Add any other platform you may support
37+
).forEach { platform ->
38+
add(platform, libs.findLibrary("androidx.room.compiler").get())
39+
}
3040
}
3141
}
3242
}

core/database/build.gradle.kts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Copyright 2024 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
111
/*
212
* Copyright 2024 Mifos Initiative
313
*
@@ -8,22 +18,50 @@
818
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
919
*/
1020
plugins {
11-
alias(libs.plugins.mifos.android.library)
12-
alias(libs.plugins.mifos.android.room)
13-
alias(libs.plugins.mifos.android.hilt)
21+
alias(libs.plugins.mifos.kmp.library)
1422
alias(libs.plugins.kotlin.serialization)
23+
alias(libs.plugins.mifos.kmp.room)
1524
}
1625

1726
android {
1827
namespace = "org.mifos.mobile.core.database"
28+
compileSdk = 35
1929

2030
defaultConfig {
2131
consumerProguardFiles("consumer-rules.pro")
2232
}
2333

34+
compileOptions {
35+
sourceCompatibility = JavaVersion.VERSION_17
36+
targetCompatibility = JavaVersion.VERSION_17
37+
}
2438
}
2539

26-
dependencies {
27-
implementation(libs.kotlinx.coroutines.core)
28-
implementation(libs.kotlinx.serialization.json)
40+
kotlin {
41+
42+
sourceSets {
43+
val desktopMain by getting
44+
45+
androidMain.dependencies {
46+
implementation(libs.koin.android)
47+
implementation(libs.androidx.room.runtime)
48+
implementation(libs.androidx.sqlite.bundled)
49+
}
50+
51+
nativeMain.dependencies {
52+
implementation(libs.androidx.room.runtime)
53+
implementation(libs.androidx.sqlite.bundled)
54+
}
55+
56+
desktopMain.dependencies {
57+
implementation(libs.androidx.room.runtime)
58+
implementation(libs.androidx.sqlite.bundled)
59+
}
60+
61+
commonMain.dependencies {
62+
implementation(libs.kotlinx.coroutines.core)
63+
implementation(libs.kotlinx.serialization.json)
64+
api(projects.core.common)
65+
}
66+
}
2967
}

core/database/schemas/org.mifos.mobile.core.database.SelfServiceDatabase/1.json renamed to core/database/schemas/org.mifos.mobile.core.database.AppDatabase/1.json

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,31 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 1,
5-
"identityHash": "0ef6ac9f8492c3e3e0026cafe51bd414",
5+
"identityHash": "534bff4d0668aa4c7b843d255397b445",
66
"entities": [
77
{
88
"tableName": "charges",
9-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `clientId` INTEGER, `chargeId` INTEGER, `name` TEXT, `dueDate` TEXT NOT NULL, `chargeTimeType` TEXT, `chargeCalculationType` TEXT, `currency` TEXT, `amount` REAL NOT NULL, `amountPaid` REAL NOT NULL, `amountWaived` REAL NOT NULL, `amountWrittenOff` REAL NOT NULL, `amountOutstanding` REAL NOT NULL, `penalty` INTEGER NOT NULL, `isActive` INTEGER NOT NULL, `isChargePaid` INTEGER NOT NULL, `isChargeWaived` INTEGER NOT NULL, `paid` INTEGER NOT NULL, `waived` INTEGER NOT NULL)",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `clientId` INTEGER, `chargeId` INTEGER, `name` TEXT, `dueDate` TEXT NOT NULL, `chargeTimeType` TEXT, `chargeCalculationType` TEXT, `currency` TEXT, `amount` REAL NOT NULL, `amountPaid` REAL NOT NULL, `amountWaived` REAL NOT NULL, `amountWrittenOff` REAL NOT NULL, `amountOutstanding` REAL NOT NULL, `penalty` INTEGER NOT NULL, `isActive` INTEGER NOT NULL, `isChargePaid` INTEGER NOT NULL, `isChargeWaived` INTEGER NOT NULL, `paid` INTEGER NOT NULL, `waived` INTEGER NOT NULL, PRIMARY KEY(`id`))",
1010
"fields": [
1111
{
1212
"fieldPath": "id",
1313
"columnName": "id",
14-
"affinity": "INTEGER",
15-
"notNull": false
14+
"affinity": "INTEGER"
1615
},
1716
{
1817
"fieldPath": "clientId",
1918
"columnName": "clientId",
20-
"affinity": "INTEGER",
21-
"notNull": false
19+
"affinity": "INTEGER"
2220
},
2321
{
2422
"fieldPath": "chargeId",
2523
"columnName": "chargeId",
26-
"affinity": "INTEGER",
27-
"notNull": false
24+
"affinity": "INTEGER"
2825
},
2926
{
3027
"fieldPath": "name",
3128
"columnName": "name",
32-
"affinity": "TEXT",
33-
"notNull": false
29+
"affinity": "TEXT"
3430
},
3531
{
3632
"fieldPath": "dueDate",
@@ -41,20 +37,17 @@
4137
{
4238
"fieldPath": "chargeTimeType",
4339
"columnName": "chargeTimeType",
44-
"affinity": "TEXT",
45-
"notNull": false
40+
"affinity": "TEXT"
4641
},
4742
{
4843
"fieldPath": "chargeCalculationType",
4944
"columnName": "chargeCalculationType",
50-
"affinity": "TEXT",
51-
"notNull": false
45+
"affinity": "TEXT"
5246
},
5347
{
5448
"fieldPath": "currency",
5549
"columnName": "currency",
56-
"affinity": "TEXT",
57-
"notNull": false
50+
"affinity": "TEXT"
5851
},
5952
{
6053
"fieldPath": "amount",
@@ -124,16 +117,14 @@
124117
}
125118
],
126119
"primaryKey": {
127-
"autoGenerate": true,
120+
"autoGenerate": false,
128121
"columnNames": [
129122
"id"
130123
]
131-
},
132-
"indices": [],
133-
"foreignKeys": []
124+
}
134125
},
135126
{
136-
"tableName": "mifos_notifications",
127+
"tableName": "mifos_notification",
137128
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timeStamp` INTEGER NOT NULL, `msg` TEXT, `read` INTEGER, PRIMARY KEY(`timeStamp`))",
138129
"fields": [
139130
{
@@ -145,30 +136,25 @@
145136
{
146137
"fieldPath": "msg",
147138
"columnName": "msg",
148-
"affinity": "TEXT",
149-
"notNull": false
139+
"affinity": "TEXT"
150140
},
151141
{
152142
"fieldPath": "read",
153143
"columnName": "read",
154-
"affinity": "INTEGER",
155-
"notNull": false
144+
"affinity": "INTEGER"
156145
}
157146
],
158147
"primaryKey": {
159148
"autoGenerate": false,
160149
"columnNames": [
161150
"timeStamp"
162151
]
163-
},
164-
"indices": [],
165-
"foreignKeys": []
152+
}
166153
}
167154
],
168-
"views": [],
169155
"setupQueries": [
170156
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
171-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0ef6ac9f8492c3e3e0026cafe51bd414')"
157+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '534bff4d0668aa4c7b843d255397b445')"
172158
]
173159
}
174160
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
package org.mifos.mobile.core.database
11+
12+
import androidx.room.Database
13+
import androidx.room.RoomDatabase
14+
import androidx.room.TypeConverters
15+
import org.mifos.mobile.core.database.dao.ChargeDao
16+
import org.mifos.mobile.core.database.dao.MifosNotificationDao
17+
import org.mifos.mobile.core.database.entity.ChargeEntity
18+
import org.mifos.mobile.core.database.entity.MifosNotificationEntity
19+
import org.mifos.mobile.core.database.utils.ChargeTypeConverters
20+
21+
@Database(
22+
entities = [
23+
ChargeEntity::class,
24+
MifosNotificationEntity::class,
25+
],
26+
version = AppDatabase.VERSION,
27+
exportSchema = true,
28+
autoMigrations = [],
29+
)
30+
@TypeConverters(ChargeTypeConverters::class)
31+
actual abstract class AppDatabase : RoomDatabase() {
32+
actual abstract val mifosNotificationDao: MifosNotificationDao
33+
actual abstract val chargeDao: ChargeDao
34+
35+
companion object {
36+
const val VERSION = 1
37+
const val DATABASE_NAME = "mifos_database.db"
38+
}
39+
}

0 commit comments

Comments
 (0)