room/testing/src/main/java/androidx/room/testing/MigrationTestHelper.java
public SupportSQLiteDatabase runMigrationsAndValidate(String name, int version,
            boolean validateDroppedTables, Migration... migrations) throws IOException {
        File dbPath = mInstrumentation.getTargetContext().getDatabasePath(name);
        if (!dbPath.exists()) {
            throw new IllegalStateException("Cannot find the database file for " + name + ". "
                    + "Before calling runMigrations, you must first create the database via "
                    + "createDatabase.");
        }
        SchemaBundle schemaBundle = loadSchema(version);
        RoomDatabase.MigrationContainer container = new RoomDatabase.MigrationContainer();
        container.addMigrations(migrations);
        DatabaseConfiguration configuration = new DatabaseConfiguration(
                mInstrumentation.getTargetContext(), name, mOpenFactory, container, null, true,
                RoomDatabase.JournalMode.TRUNCATE, true, Collections.<Integer>emptySet());
        RoomOpenHelper roomOpenHelper = new RoomOpenHelper(configuration,
                new MigratingDelegate(schemaBundle.getDatabase(), validateDroppedTables),
                // we pass the same hash twice since an old schema does not necessarily have
                // a legacy hash and we would not even persist it.
                schemaBundle.getDatabase().getIdentityHash(),
                schemaBundle.getDatabase().getIdentityHash());
        return openDatabase(name, roomOpenHelper);
    }
/**
     * Runs the given set of migrations on the provided database.
     * <p>
     * It uses the same algorithm that Room uses to choose migrations so the migrations instances
     * that are provided to this method must be sufficient to bring the database from current
     * version to the desired version.
     * <p>
     * After the migration, the method validates the database schema to ensure that migration
     * result matches the expected schema. Handling of dropped tables depends on the
     * {@code validateDroppedTables} argument. If set to true, the verification will fail if it
     * finds a table that is not registered in the Database. If set to false, extra tables in the
     * database will be ignored (this is the runtime library behavior).
     *
     * @param name                  The database name. You must first create this database via
     *                              {@link #createDatabase(String, int)}.
     * @param version               The final version after applying the migrations.
     * @param validateDroppedTables If set to true, validation will fail if the database has
     *                              unknown
     *                              tables.
     * @param migrations            The list of available migrations.
     * @throws IOException           If it cannot find the schema for {@code toVersion}.
     * @throws IllegalStateException If the schema validation fails.
     */
Runs the given set of migrations on the provided database.

It uses the same algorithm that Room uses to choose migrations so the migrations instances
that are provided to this method must be sufficient to bring the database from current
version to the desired version.

After the migration, the method validates the database schema to ensure that migration
result matches the expected schema. Handling of dropped tables depends on the
validateDroppedTables argument. If set to true, the verification will fail if it
finds a table that is not registered in the Database. If set to false, extra tables in the
database will be ignored (this is the runtime library behavior).

@param name                  The database name. You must first create this database via
#createDatabase(String, int).
@param version               The final version after applying the migrations.
@param validateDroppedTables If set to true, validation will fail if the database has
unknown
tables.
@param migrations            The list of available migrations.
@throws IOException           If it cannot find the schema for  toVersion.
@throws IllegalStateException If the schema validation fails.
Runs the given set of migrations on the provided database . It uses the same algorithm that Room uses to choose migrations so the migrations instances that are provided to this method must be sufficient to bring the database from current version to the desired version . After the migration the method validates the database schema to ensure that migration result matches the expected schema . Handling of dropped tables depends on the validateDroppedTables argument . If set to true the verification will fail if it finds a table that is not registered in the Database . If set to false extra tables in the database will be ignored ( this is the runtime library behavior ) . @param name The database name . You must first create this database via #createDatabase ( String int ) . @param version The final version after applying the migrations . @param validateDroppedTables If set to true validation will fail if the database has unknown tables . @param migrations The list of available migrations . @throws IOException If it cannot find the schema for toVersion . @throws IllegalStateException If the schema validation fails .
public SupportSQLiteDatabase runMigrationsAndValidate(String name, int version,
            boolean validateDroppedTables, Migration... migrations) throws IOException {
        File dbPath = mInstrumentation.getTargetContext().getDatabasePath(name);
        if (!dbPath.exists()) {
            throw new IllegalStateException("Cannot find the database file for " + name + ". "
                    + "Before calling runMigrations, you must first create the database via "
                    + "createDatabase.");
        }
        SchemaBundle schemaBundle = loadSchema(version);
        RoomDatabase.MigrationContainer container = new RoomDatabase.MigrationContainer();
        container.addMigrations(migrations);
        DatabaseConfiguration configuration = new DatabaseConfiguration(
                mInstrumentation.getTargetContext(), name, mOpenFactory, container, null, true,
                RoomDatabase.JournalMode.TRUNCATE, true, Collections.<Integer>emptySet());
        RoomOpenHelper roomOpenHelper = new RoomOpenHelper(configuration,
                new MigratingDelegate(schemaBundle.getDatabase(), validateDroppedTables),
                schemaBundle.getDatabase().getIdentityHash(),
                schemaBundle.getDatabase().getIdentityHash());
        return openDatabase(name, roomOpenHelper);
    }
public SupportSQLiteDatabase runMigrationsAndValidate ( String name , int version , boolean validateDroppedTables , Migration ... migrations ) throws IOException { File dbPath = mInstrumentation . getTargetContext ( ) . getDatabasePath ( name ) ; if ( ! dbPath . exists ( ) ) { throw new IllegalStateException ( "Cannot find the database file for " + name + ". " + "Before calling runMigrations, you must first create the database via " + "createDatabase." ) ; } SchemaBundle schemaBundle = loadSchema ( version ) ; RoomDatabase . MigrationContainer container = new RoomDatabase . MigrationContainer ( ) ; container . addMigrations ( migrations ) ; DatabaseConfiguration configuration = new DatabaseConfiguration ( mInstrumentation . getTargetContext ( ) , name , mOpenFactory , container , null , true , RoomDatabase . JournalMode . TRUNCATE , true , Collections . < Integer > emptySet ( ) ) ; RoomOpenHelper roomOpenHelper = new RoomOpenHelper ( configuration , new MigratingDelegate ( schemaBundle . getDatabase ( ) , validateDroppedTables ) , schemaBundle . getDatabase ( ) . getIdentityHash ( ) , schemaBundle . getDatabase ( ) . getIdentityHash ( ) ) ; return openDatabase ( name , roomOpenHelper ) ; }
Runs the given set of migrations on the provided database.
Runs the given set of migrations on the provided database .
// we pass the same hash twice since an old schema does not necessarily have // a legacy hash and we would not even persist it.