Fixed
Status Update
Comments
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com> #2
next version will start validating indices.
Unfortunately, necessary pragma was added only in 2015 so in older devices, we'll ignore the index information during validation.
https://www.sqlite.org/src/timeline?yw=2015-05&n=16&y=a&u=drh
Unfortunately, necessary pragma was added only in 2015 so in older devices, we'll ignore the index information during validation.
Description
Version used: 1.0.0-alpha3
Devices/Android versions reproduced on: Nexus 5X (ODP3)
While runMigrationsAndValidate() does check for invalid table structures, it does not check for the existence or validity of indexes.
Suppose the real migration should be:
static final Migration FROM_1_TO_2=new Migration(1,2) {
@Override
public void migrate(SupportSQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS `lodgings` (`id` TEXT, `title` TEXT, `duration` INTEGER, `priority` INTEGER, `startTime` INTEGER, `creationTime` INTEGER, `updateTime` INTEGER, `address` TEXT, `tripId` TEXT, PRIMARY KEY(`id`), FOREIGN KEY(`tripId`) REFERENCES `trips`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
db.execSQL("CREATE INDEX `index_lodgings_tripId` ON `lodgings` (`tripId`)");
db.execSQL("CREATE TABLE IF NOT EXISTS `flights` (`id` TEXT, `title` TEXT, `duration` INTEGER, `priority` INTEGER, `startTime` INTEGER, `creationTime` INTEGER, `updateTime` INTEGER, `departingAirport` TEXT, `arrivingAirport` TEXT, `airlineCode` TEXT, `flightNumber` TEXT, `seatNumber` TEXT, `tripId` TEXT, PRIMARY KEY(`id`), FOREIGN KEY(`tripId`) REFERENCES `trips`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
db.execSQL("CREATE INDEX `index_flights_tripId` ON `flights` (`tripId`)");
}
};
This migration passes the runMigrationsAndValidate() test:
static final Migration BROKEN_1_TO_2=new Migration(1,2) {
@Override
public void migrate(SupportSQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS `lodgings` (`id` TEXT, `title` TEXT, `duration` INTEGER, `priority` INTEGER, `startTime` INTEGER, `creationTime` INTEGER, `updateTime` INTEGER, `address` TEXT, `tripId` TEXT, PRIMARY KEY(`id`), FOREIGN KEY(`tripId`) REFERENCES `trips`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
db.execSQL("CREATE TABLE IF NOT EXISTS `flights` (`id` TEXT, `title` TEXT, `duration` INTEGER, `priority` INTEGER, `startTime` INTEGER, `creationTime` INTEGER, `updateTime` INTEGER, `departingAirport` TEXT, `arrivingAirport` TEXT, `airlineCode` TEXT, `flightNumber` TEXT, `seatNumber` TEXT, `tripId` TEXT, PRIMARY KEY(`id`), FOREIGN KEY(`tripId`) REFERENCES `trips`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
}
};
...despite the fact that neither index found in the schema JSON was created.
The attached project illustrates the problem. The MigrationTests right now uses BROKEN_1_TO_2, which should fail but does not.