Skip to content

Commit

Permalink
feat(core:database): Migrate database module to KMP
Browse files Browse the repository at this point in the history
  • Loading branch information
HekmatullahAmin committed Jan 22, 2025
1 parent e43095b commit b39f906
Show file tree
Hide file tree
Showing 44 changed files with 955 additions and 144 deletions.
15 changes: 10 additions & 5 deletions androidApp/dependencies/demoDebugRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,18 @@ 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-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
15 changes: 10 additions & 5 deletions androidApp/dependencies/demoReleaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ 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-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
15 changes: 10 additions & 5 deletions androidApp/dependencies/prodDebugRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,18 @@ 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-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
15 changes: 10 additions & 5 deletions androidApp/dependencies/prodReleaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ 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-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
76 changes: 70 additions & 6 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* 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
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

/*
* Copyright 2024 Mifos Initiative
*
Expand All @@ -8,22 +23,71 @@
* 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.room)
alias(libs.plugins.ksp)
}

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

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

buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

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

room {
schemaDirectory("$projectDir/schemas")
}

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)
}

dependencies {
listOf(
"kspAndroid",
"kspIosArm64",
"kspIosX64",
"kspIosSimulatorArm64",
// Add any other platform you may support
).forEach {
add(it, libs.androidx.room.compiler)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "534bff4d0668aa4c7b843d255397b445",
"entities": [
{
"tableName": "charges",
"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"
},
{
"fieldPath": "clientId",
"columnName": "clientId",
"affinity": "INTEGER"
},
{
"fieldPath": "chargeId",
"columnName": "chargeId",
"affinity": "INTEGER"
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT"
},
{
"fieldPath": "dueDate",
"columnName": "dueDate",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "chargeTimeType",
"columnName": "chargeTimeType",
"affinity": "TEXT"
},
{
"fieldPath": "chargeCalculationType",
"columnName": "chargeCalculationType",
"affinity": "TEXT"
},
{
"fieldPath": "currency",
"columnName": "currency",
"affinity": "TEXT"
},
{
"fieldPath": "amount",
"columnName": "amount",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "amountPaid",
"columnName": "amountPaid",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "amountWaived",
"columnName": "amountWaived",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "amountWrittenOff",
"columnName": "amountWrittenOff",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "amountOutstanding",
"columnName": "amountOutstanding",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "penalty",
"columnName": "penalty",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isActive",
"columnName": "isActive",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isChargePaid",
"columnName": "isChargePaid",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isChargeWaived",
"columnName": "isChargeWaived",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "paid",
"columnName": "paid",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "waived",
"columnName": "waived",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "mifos_notification",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timeStamp` INTEGER NOT NULL, `msg` TEXT, `read` INTEGER, PRIMARY KEY(`timeStamp`))",
"fields": [
{
"fieldPath": "timeStamp",
"columnName": "timeStamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "msg",
"columnName": "msg",
"affinity": "TEXT"
},
{
"fieldPath": "read",
"columnName": "read",
"affinity": "INTEGER"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"timeStamp"
]
}
}
],
"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, '534bff4d0668aa4c7b843d255397b445')"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Mifos Initiative
* 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
Expand All @@ -23,19 +23,17 @@ import org.mifos.mobile.core.database.utils.ChargeTypeConverters
ChargeEntity::class,
MifosNotificationEntity::class,
],
version = SelfServiceDatabase.VERSION,
version = AppDatabase.VERSION,
exportSchema = true,
autoMigrations = [],
)
@TypeConverters(ChargeTypeConverters::class)
abstract class SelfServiceDatabase : RoomDatabase() {

abstract fun mifosNotificationDao(): MifosNotificationDao

abstract fun chargeDao(): ChargeDao
actual abstract class AppDatabase : RoomDatabase() {
actual abstract val mifosNotificationDao: MifosNotificationDao
actual abstract val chargeDao: ChargeDao

companion object {
// Update the version number if you change the schema
const val VERSION = 1
const val DATABASE_NAME = "mifos_database.db"
}
}
Loading

0 comments on commit b39f906

Please sign in to comment.