Skip to content

Commit

Permalink
feat(core:database): Migrate database module to KMP (openMF#2752)
Browse files Browse the repository at this point in the history
Co-authored-by: Sk Niyaj Ali <[email protected]>
  • Loading branch information
HekmatullahAmin and niyajali authored Jan 26, 2025
1 parent c67f9d4 commit c759137
Show file tree
Hide file tree
Showing 46 changed files with 810 additions and 183 deletions.
16 changes: 11 additions & 5 deletions androidApp/dependencies/demoDebugRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
androidx.profileinstaller:profileinstaller:1.4.1
androidx.resourceinspection:resourceinspection-annotation:1.0.1
androidx.room:room-common:2.6.1
androidx.room:room-ktx:2.6.1
androidx.room:room-runtime:2.6.1
androidx.room:room-common-jvm:2.7.0-alpha12
androidx.room:room-common:2.7.0-alpha12
androidx.room:room-ktx:2.7.0-alpha12
androidx.room:room-runtime-android:2.7.0-alpha12
androidx.room:room-runtime:2.7.0-alpha12
androidx.savedstate:savedstate-ktx:1.2.1
androidx.savedstate:savedstate:1.2.1
androidx.sqlite:sqlite-framework:2.4.0
androidx.sqlite:sqlite:2.4.0
androidx.sqlite:sqlite-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
androidx.sqlite:sqlite-framework:2.5.0-alpha12
androidx.sqlite:sqlite:2.5.0-alpha12
androidx.startup:startup-runtime:1.1.1
androidx.tracing:tracing-ktx:1.2.0
androidx.tracing:tracing:1.2.0
Expand Down
16 changes: 11 additions & 5 deletions androidApp/dependencies/demoReleaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
androidx.profileinstaller:profileinstaller:1.4.1
androidx.resourceinspection:resourceinspection-annotation:1.0.1
androidx.room:room-common:2.6.1
androidx.room:room-ktx:2.6.1
androidx.room:room-runtime:2.6.1
androidx.room:room-common-jvm:2.7.0-alpha12
androidx.room:room-common:2.7.0-alpha12
androidx.room:room-ktx:2.7.0-alpha12
androidx.room:room-runtime-android:2.7.0-alpha12
androidx.room:room-runtime:2.7.0-alpha12
androidx.savedstate:savedstate-ktx:1.2.1
androidx.savedstate:savedstate:1.2.1
androidx.sqlite:sqlite-framework:2.4.0
androidx.sqlite:sqlite:2.4.0
androidx.sqlite:sqlite-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
androidx.sqlite:sqlite-framework:2.5.0-alpha12
androidx.sqlite:sqlite:2.5.0-alpha12
androidx.startup:startup-runtime:1.1.1
androidx.tracing:tracing-ktx:1.2.0
androidx.tracing:tracing:1.2.0
Expand Down
16 changes: 11 additions & 5 deletions androidApp/dependencies/prodDebugRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
androidx.profileinstaller:profileinstaller:1.4.1
androidx.resourceinspection:resourceinspection-annotation:1.0.1
androidx.room:room-common:2.6.1
androidx.room:room-ktx:2.6.1
androidx.room:room-runtime:2.6.1
androidx.room:room-common-jvm:2.7.0-alpha12
androidx.room:room-common:2.7.0-alpha12
androidx.room:room-ktx:2.7.0-alpha12
androidx.room:room-runtime-android:2.7.0-alpha12
androidx.room:room-runtime:2.7.0-alpha12
androidx.savedstate:savedstate-ktx:1.2.1
androidx.savedstate:savedstate:1.2.1
androidx.sqlite:sqlite-framework:2.4.0
androidx.sqlite:sqlite:2.4.0
androidx.sqlite:sqlite-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
androidx.sqlite:sqlite-framework:2.5.0-alpha12
androidx.sqlite:sqlite:2.5.0-alpha12
androidx.startup:startup-runtime:1.1.1
androidx.tracing:tracing-ktx:1.2.0
androidx.tracing:tracing:1.2.0
Expand Down
16 changes: 11 additions & 5 deletions androidApp/dependencies/prodReleaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@ androidx.privacysandbox.ads:ads-adservices-java:1.0.0-beta05
androidx.privacysandbox.ads:ads-adservices:1.0.0-beta05
androidx.profileinstaller:profileinstaller:1.4.1
androidx.resourceinspection:resourceinspection-annotation:1.0.1
androidx.room:room-common:2.6.1
androidx.room:room-ktx:2.6.1
androidx.room:room-runtime:2.6.1
androidx.room:room-common-jvm:2.7.0-alpha12
androidx.room:room-common:2.7.0-alpha12
androidx.room:room-ktx:2.7.0-alpha12
androidx.room:room-runtime-android:2.7.0-alpha12
androidx.room:room-runtime:2.7.0-alpha12
androidx.savedstate:savedstate-ktx:1.2.1
androidx.savedstate:savedstate:1.2.1
androidx.sqlite:sqlite-framework:2.4.0
androidx.sqlite:sqlite:2.4.0
androidx.sqlite:sqlite-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled-android:2.5.0-alpha12
androidx.sqlite:sqlite-bundled:2.5.0-alpha12
androidx.sqlite:sqlite-framework-android:2.5.0-alpha12
androidx.sqlite:sqlite-framework:2.5.0-alpha12
androidx.sqlite:sqlite:2.5.0-alpha12
androidx.startup:startup-runtime:1.1.1
androidx.tracing:tracing-ktx:1.2.0
androidx.tracing:tracing:1.2.0
Expand Down
6 changes: 3 additions & 3 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ gradlePlugin {
id = "mifos.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
}
register("androidRoom") {
id = "mifos.android.room"
implementationClass = "AndroidRoomConventionPlugin"
register("kmpRoom") {
id = "mifos.kmp.room"
implementationClass = "KMPRoomConventionPlugin"
}

// Utility Plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.mifos.mobile.libs

class AndroidRoomConventionPlugin : Plugin<Project> {
class KMPRoomConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("androidx.room")
Expand All @@ -26,7 +26,17 @@ class AndroidRoomConventionPlugin : Plugin<Project> {
dependencies {
"implementation"(libs.findLibrary("androidx.room.runtime").get())
"implementation"(libs.findLibrary("androidx.room.ktx").get())
"ksp"(libs.findLibrary("androidx.room.compiler").get())
// Adding ksp dependencies for multiple platforms
listOf(
"kspDesktop",
"kspAndroid",
"kspIosArm64",
"kspIosX64",
"kspIosSimulatorArm64",
// Add any other platform you may support
).forEach { platform ->
add(platform, libs.findLibrary("androidx.room.compiler").get())
}
}
}
}
Expand Down
50 changes: 44 additions & 6 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/

/*
* Copyright 2024 Mifos Initiative
*
Expand All @@ -8,22 +18,50 @@
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.library)
alias(libs.plugins.mifos.android.room)
alias(libs.plugins.mifos.android.hilt)
alias(libs.plugins.mifos.kmp.library)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.mifos.kmp.room)
}

android {
namespace = "org.mifos.mobile.core.database"
compileSdk = 35

defaultConfig {
consumerProguardFiles("consumer-rules.pro")
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.serialization.json)
kotlin {

sourceSets {
val desktopMain by getting

androidMain.dependencies {
implementation(libs.koin.android)
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.sqlite.bundled)
}

nativeMain.dependencies {
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.sqlite.bundled)
}

desktopMain.dependencies {
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.sqlite.bundled)
}

commonMain.dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.serialization.json)
api(projects.core.common)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,31 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "0ef6ac9f8492c3e3e0026cafe51bd414",
"identityHash": "534bff4d0668aa4c7b843d255397b445",
"entities": [
{
"tableName": "charges",
"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)",
"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`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
"affinity": "INTEGER"
},
{
"fieldPath": "clientId",
"columnName": "clientId",
"affinity": "INTEGER",
"notNull": false
"affinity": "INTEGER"
},
{
"fieldPath": "chargeId",
"columnName": "chargeId",
"affinity": "INTEGER",
"notNull": false
"affinity": "INTEGER"
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
"affinity": "TEXT"
},
{
"fieldPath": "dueDate",
Expand All @@ -41,20 +37,17 @@
{
"fieldPath": "chargeTimeType",
"columnName": "chargeTimeType",
"affinity": "TEXT",
"notNull": false
"affinity": "TEXT"
},
{
"fieldPath": "chargeCalculationType",
"columnName": "chargeCalculationType",
"affinity": "TEXT",
"notNull": false
"affinity": "TEXT"
},
{
"fieldPath": "currency",
"columnName": "currency",
"affinity": "TEXT",
"notNull": false
"affinity": "TEXT"
},
{
"fieldPath": "amount",
Expand Down Expand Up @@ -124,16 +117,14 @@
}
],
"primaryKey": {
"autoGenerate": true,
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
},
{
"tableName": "mifos_notifications",
"tableName": "mifos_notification",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timeStamp` INTEGER NOT NULL, `msg` TEXT, `read` INTEGER, PRIMARY KEY(`timeStamp`))",
"fields": [
{
Expand All @@ -145,30 +136,25 @@
{
"fieldPath": "msg",
"columnName": "msg",
"affinity": "TEXT",
"notNull": false
"affinity": "TEXT"
},
{
"fieldPath": "read",
"columnName": "read",
"affinity": "INTEGER",
"notNull": false
"affinity": "INTEGER"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"timeStamp"
]
},
"indices": [],
"foreignKeys": []
}
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0ef6ac9f8492c3e3e0026cafe51bd414')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '534bff4d0668aa4c7b843d255397b445')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.database

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import org.mifos.mobile.core.database.dao.ChargeDao
import org.mifos.mobile.core.database.dao.MifosNotificationDao
import org.mifos.mobile.core.database.entity.ChargeEntity
import org.mifos.mobile.core.database.entity.MifosNotificationEntity
import org.mifos.mobile.core.database.utils.ChargeTypeConverters

@Database(
entities = [
ChargeEntity::class,
MifosNotificationEntity::class,
],
version = AppDatabase.VERSION,
exportSchema = true,
autoMigrations = [],
)
@TypeConverters(ChargeTypeConverters::class)
actual abstract class AppDatabase : RoomDatabase() {
actual abstract val mifosNotificationDao: MifosNotificationDao
actual abstract val chargeDao: ChargeDao

companion object {
const val VERSION = 1
const val DATABASE_NAME = "mifos_database.db"
}
}
Loading

0 comments on commit c759137

Please sign in to comment.