# Migration

Artifact: [androidx.room3:room3-runtime](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/migration/Migration.kt+class:androidx.room3.migration.Migration) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

*** ** * ** ***

Common/All
- Cmn

  ```
  abstract class Migration
  ```

*** ** * ** ***

Base class for a database migration.

Each migration can move between 2 versions that are defined by `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#startVersion()` and `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#endVersion()`.

A migration can handle more than 1 version (e.g. if you have a faster path to choose when going version 3 to 5 without going to version 4). If Room opens a database at version 3 and latest version is 5, Room will use the migration object that can migrate from 3 to 5 instead of 3 to 4 and 4 to 5.

If there are not enough migrations provided to move from the current version to the latest version, Room will might clear the database and recreate if destructive migrations are enabled.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#Migration(kotlin.Int,kotlin.Int)(startVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, endVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a new migration between `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#startVersion()` and `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#endVersion()` inclusive. | Cmn |

| ### Public functions |
|---|---|---|
| `abstract suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#migrate(androidx.sqlite.SQLiteConnection)(connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection)` Should run the necessary migrations. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#endVersion()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#startVersion()` | Cmn |

## Public constructors

### Migration

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
Migration(startVersion: Int, endVersion: Int)
```

Creates a new migration between `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#startVersion()` and `https://developer.android.com/reference/kotlin/androidx/room3/migration/Migration#endVersion()` inclusive.

## Public functions

### migrate

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
abstract suspend fun migrate(connection: SQLiteConnection): Unit
```

Should run the necessary migrations.

This function is already called inside a transaction and that transaction might actually be a composite transaction of all necessary `Migration`s.

| Parameters |
|---|---|
| `connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` | The database connection |

## Public properties

### endVersion

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
val endVersion: Int
```

### startVersion

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
val startVersion: Int
```