RoomDatabase.MigrationContainer

open class RoomDatabase.MigrationContainer


A container to hold migrations. It also allows querying its contents to find migrations between two versions.

Summary

Public constructors

Public functions

open Unit

Adds the given migrations to the list of available migrations.

open Unit
addMigrations(vararg migrations: Migration)

Adds the given migrations to the list of available migrations.

Boolean
contains(startVersion: Int, endVersion: Int)

Indicates if the given migration is contained within the MigrationContainer based on its start-end versions.

open List<Migration>?
findMigrationPath(start: Int, end: Int)

Finds the list of migrations that should be run to move from start version to end version.

open Map<IntMap<IntMigration>>

Returns the map of available migrations where the key is the start version of the migration, and the value is a map of (end version -> Migration).

Public constructors

MigrationContainer

Added in 2.0.0
MigrationContainer()

Public functions

addMigrations

Added in 2.4.0
open fun addMigrations(migrations: List<Migration>): Unit

Adds the given migrations to the list of available migrations. If 2 migrations have the same start-end versions, the latter migration overrides the previous one.

Parameters
migrations: List<Migration>

List of available migrations.

addMigrations

Added in 2.0.0
open fun addMigrations(vararg migrations: Migration): Unit

Adds the given migrations to the list of available migrations. If 2 migrations have the same start-end versions, the latter migration overrides the previous one.

Parameters
vararg migrations: Migration

List of available migrations.

contains

Added in 2.5.0
fun contains(startVersion: Int, endVersion: Int): Boolean

Indicates if the given migration is contained within the MigrationContainer based on its start-end versions.

Parameters
startVersion: Int

Start version of the migration.

endVersion: Int

End version of the migration

Returns
Boolean

True if it contains a migration with the same start-end version, false otherwise.

findMigrationPath

Added in 2.0.0
open fun findMigrationPath(start: Int, end: Int): List<Migration>?

Finds the list of migrations that should be run to move from start version to end version.

Parameters
start: Int

The current database version

end: Int

The target database version

Returns
List<Migration>?

An ordered list of Migration objects that should be run to migrate between the given versions. If a migration path cannot be found, returns null.

getMigrations

Added in 2.4.0
open fun getMigrations(): Map<IntMap<IntMigration>>

Returns the map of available migrations where the key is the start version of the migration, and the value is a map of (end version -> Migration).

Returns
Map<IntMap<IntMigration>>

Map of migrations keyed by the start version