kotlin-migration
2.1.4indexedEnables streamlined program migrations by offering a `Migrator` framework to execute custom migration logic. Supports `VersionMigration` and `ConditionalMigration` types, facilitating efficient version transitions.
Enables streamlined program migrations by offering a `Migrator` framework to execute custom migration logic. Supports `VersionMigration` and `ConditionalMigration` types, facilitating efficient version transitions.
A Kotlin library to enable easier program migrations, inspired by AndroidX Room
dependencies {
implementation("io.github.boswelja.migration:migration-core:$version")
}
MigratorThe basis of this library is a Migrator, that will run any Migration you give it. To create a Migrator, you should create your own class extending Migrator.
class MigrationManager : Migrator(
currentVersion = 1,
migrations = listOf(
// Your migrations here
)
) {
override suspend fun getOldVersion(): Int {
// You should fetch your previous version here
return 1
}
}
That's it! You can then call migrate() on an instance of your Migrator implementation.
val migrationManager = MigrationManager()
coroutineScope.launch {
migrationManager.migrate()
}
Currently, this library provides 2 types of migrations, VersionMigration and ConditionalMigration. Both should be passed into your Migrator constructor.
VersionMigrationval migration1_2 = object : VersionMigration(fromVersion = 1, toVersion = 2) {
override suspend fun migrate(): Boolean {
// Do your migration here
return true
}
}
ConditionalMigrationval migration1_2 = object : ConditionalMigration() {
override suspend fun shouldMigrate: {
shouldMigrate = ...
shouldMigrate
}
: {
}
}
You can implement the Migration interface on a class to build your own migration with more complex logic.
abstract class VersionMigration(
val fromVersion: Int,
final override val toVersion: Int
) : Migration {
final : {
fromVersion == .fromVersion
}
}
Surfaced from shared tags and platforms — no rankings paid for.