Stay organized with collections
Save and categorize content based on your preferences.
added in
version 1.1.0
belongs to Maven artifact android.arch.persistence.room:runtime:1.1.0-beta2
Migration
public
abstract
class
Migration
extends Object
java.lang.Object
|
↳ |
android.arch.persistence.room.migration.Migration
|
Base class for a database migration.
Each migration can move between 2 versions that are defined by startVersion
and
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 clear the database and recreate so even if you have no changes between 2
versions, you should still provide a Migration object to the builder.
Summary
Public constructors |
Migration(int startVersion, int endVersion)
Creates a new migration between startVersion and endVersion .
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Fields
endVersion
int endVersion
startVersion
int startVersion
Public constructors
Migration
Migration (int startVersion,
int endVersion)
Creates a new migration between startVersion
and endVersion
.
Parameters |
startVersion |
int : The start version of the database. |
endVersion |
int : The end version of the database after this migration is applied.
|
Public methods
migrate
void migrate (SupportSQLiteDatabase database)
Should run the necessary migrations.
This class cannot access any generated Dao in this method.
This method is already called inside a transaction and that transaction might actually be a
composite transaction of all necessary Migration
s.
Parameters |
database |
SupportSQLiteDatabase : The database instance
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Migration\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \nbelongs to Maven artifact android.arch.persistence.room:runtime:1.1.0-beta2 \nSummary: [Fields](#lfields) \\| [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nMigration\n=========\n\n| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\\*](/jetpack/androidx/migrate) packages. See [androidx.room.migration.Migration](/reference/androidx/room/migration/Migration) instead.\n\n\n`\npublic\n\n\nabstract\nclass\nMigration\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|---------------------------------------------------|\n| java.lang.Object ||\n| ↳ | android.arch.persistence.room.migration.Migration |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nBase class for a database migration.\n\n\nEach migration can move between 2 versions that are defined by [startVersion](/reference/android/arch/persistence/room/migration/Migration#startVersion) and\n[endVersion](/reference/android/arch/persistence/room/migration/Migration#endVersion).\n\n\nA migration can handle more than 1 version (e.g. if you have a faster path to choose when\ngoing version 3 to 5 without going to version 4). If Room opens a database at version\n3 and latest version is \\\u003e= 5, Room will use the migration object that can migrate from\n3 to 5 instead of 3 to 4 and 4 to 5.\n\n\nIf there are not enough migrations provided to move from the current version to the latest\nversion, Room will clear the database and recreate so even if you have no changes between 2\nversions, you should still provide a Migration object to the builder.\n\nSummary\n-------\n\n| ### Fields ||\n|---------------------|-------------------------------------------------------------------------------------------|\n| ` public final int` | [endVersion](/reference/android/arch/persistence/room/migration/Migration#endVersion) |\n| ` public final int` | [startVersion](/reference/android/arch/persistence/room/migration/Migration#startVersion) |\n\n| ### Public constructors ||\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[Migration](/reference/android/arch/persistence/room/migration/Migration#Migration(int, int))`(int startVersion, int endVersion) ` Creates a new migration between `startVersion` and `endVersion`. |\n\n| ### Public methods ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[migrate](/reference/android/arch/persistence/room/migration/Migration#migrate(android.arch.persistence.db.SupportSQLiteDatabase))`(`[SupportSQLiteDatabase](/reference/android/arch/persistence/db/SupportSQLiteDatabase)` database) ` Should run the necessary migrations. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nFields\n------\n\n### endVersion\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nint endVersion\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### startVersion\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nint startVersion\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic constructors\n-------------------\n\n### Migration\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nMigration (int startVersion, \n int endVersion)\n```\n\nCreates a new migration between `startVersion` and `endVersion`.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|--------------------------------------------------------------------------------|\n| `startVersion` | `int`: The start version of the database. \u003cbr /\u003e |\n| `endVersion` | `int`: The end version of the database after this migration is applied. \u003cbr /\u003e |\n\nPublic methods\n--------------\n\n### migrate\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nvoid migrate (SupportSQLiteDatabase database)\n```\n\nShould run the necessary migrations.\n\n\nThis class cannot access any generated Dao in this method.\n\n\nThis method is already called inside a transaction and that transaction might actually be a\ncomposite transaction of all necessary `Migration`s.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-------------------------------------------------------|\n| `database` | `SupportSQLiteDatabase`: The database instance \u003cbr /\u003e |\n\n-\n\n Classes\n -------\n\n - [Migration](/reference/android/arch/persistence/room/migration/Migration)"]]