destructiveMigration

suspend fun SqlSchema<QueryResult.AsyncValue<Unit>>.destructiveMigration(driver: SqlDriver): QueryResult.AsyncValue<Unit>

Performs a destructive migration on the provided SQL driver.

This method drops all tables from the database, excluding system tables like sqlite_sequence and android_metadata. After all tables are dropped, the schema is recreated using the create method.

Receiver

The SqlSchema that defines the structure of the database.

Return

A QueryResult.AsyncValue<Unit> representing the result of the migration process. The schema is recreated after all tables are dropped.

Example:

object DestructiveMigrationSchema :
SqlSchema<QueryResult.AsyncValue<Unit>> by MyClientDatabase.Schema {
override fun migrate(
driver: SqlDriver, oldVersion: Long, newVersion: Long, vararg callbacks: AfterVersion
): QueryResult.AsyncValue<Unit> {
Log.d(
MyClientManager.TAG,
"Database version changed ($oldVersion -> $newVersion), performing destructive migration"
)
return destructiveMigration(driver)
}
}

fun MynClientDatabase.Companion.DestructiveMigrationSchema():
SqlSchema<QueryResult.AsyncValue<Unit>> = DestructiveMigrationSchema

In this example, the DestructiveMigrationSchema object implements the SqlSchema interface. When the migrate method detects a version change, it logs the change and invokes destructiveMigration(driver) to drop and recreate all tables.

Parameters

driver

The SqlDriver instance that will be used to execute the SQL commands.


fun SqlSchema<QueryResult.AsyncValue<Unit>>.destructiveMigration(): SqlSchema<QueryResult.AsyncValue<Unit>>