AutoMigration class

Declares an automatic migration of a Database from the schema version from to to, like Room's @AutoMigration.

Froom detects the changes between the schemas of both versions, which it exports to the schema directory when generating the code, and generates a migration performing them. Commit the exported schema files, as they are required to generate the migrations of later versions.

Deleted or renamed tables and columns can't be distinguished from each other, so they have to be declared on a spec class annotated with RenameTable, RenameColumn, DeleteTable or DeleteColumn. Its onPostMigrate method is called after the automatic migration, e.g. for migrating data.

@Database(
  version: 3,
  entities: [Song, Artist],
  autoMigrations: [
    AutoMigration(from: 1, to: 2),
    AutoMigration(from: 2, to: 3, spec: MusicAutoMigrationSpec),
  ],
)
abstract class MusicDatabase extends FroomDatabase {}

@DeleteTable(tableName: 'Album')
@RenameTable(fromTableName: 'Singer', toTableName: 'Artist')
@RenameColumn(
  tableName: 'Song',
  fromColumnName: 'songName',
  toColumnName: 'songTitle',
)
@DeleteColumn(tableName: 'Song', columnName: 'genre')
class MusicAutoMigrationSpec extends AutoMigrationSpec {}

Constructors

AutoMigration({required int from, required int to, Type? spec})
Declares an automatic migration.
const

Properties

from → int
The version of the database schema to migrate from.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
spec → Type?
The class extending AutoMigrationSpec, which declares renamed and deleted tables and columns.
final
to → int
The version of the database schema to migrate to.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited