@@ -95,20 +95,14 @@ - (void)testAddsTargetGlobal {
9595}
9696
9797- (void )testSetsVersionNumber {
98- {
99- LevelDbTransaction transaction (_db.get (), " testSetsVersionNumber before" );
100- SchemaVersion initial = LevelDbMigrations::ReadSchemaVersion (&transaction);
101- XCTAssertEqual (0 , initial, " No version should be equivalent to 0" );
102- }
98+ SchemaVersion initial = LevelDbMigrations::ReadSchemaVersion (_db.get ());
99+ XCTAssertEqual (0 , initial, " No version should be equivalent to 0" );
103100
104- {
105- // Pick an arbitrary high migration number and migrate to it.
106- LevelDbMigrations::RunMigrations (_db.get ());
101+ // Pick an arbitrary high migration number and migrate to it.
102+ LevelDbMigrations::RunMigrations (_db.get ());
107103
108- LevelDbTransaction transaction (_db.get (), " testSetsVersionNumber after" );
109- SchemaVersion actual = LevelDbMigrations::ReadSchemaVersion (&transaction);
110- XCTAssertGreaterThan (actual, 0 , @" Expected to migrate to a schema version > 0" );
111- }
104+ SchemaVersion actual = LevelDbMigrations::ReadSchemaVersion (_db.get ());
105+ XCTAssertGreaterThan (actual, 0 , @" Expected to migrate to a schema version > 0" );
112106}
113107
114108#define ASSERT_NOT_FOUND (transaction, key ) \
@@ -366,6 +360,25 @@ - (void)testRemovesMutationBatches {
366360 }
367361}
368362
363+ - (void )testCanDowngrade {
364+ // First, run all of the migrations
365+ LevelDbMigrations::RunMigrations (_db.get ());
366+
367+ LevelDbMigrations::SchemaVersion latestVersion = LevelDbMigrations::ReadSchemaVersion (_db.get ());
368+
369+ // Downgrade to an early version.
370+ LevelDbMigrations::SchemaVersion downgradeVersion = 1 ;
371+ LevelDbMigrations::RunMigrations (_db.get (), downgradeVersion);
372+ LevelDbMigrations::SchemaVersion postDowngradeVersion =
373+ LevelDbMigrations::ReadSchemaVersion (_db.get ());
374+ XCTAssertEqual (downgradeVersion, postDowngradeVersion);
375+
376+ // Verify that we can upgrade again to the latest version.
377+ LevelDbMigrations::RunMigrations (_db.get ());
378+ LevelDbMigrations::SchemaVersion finalVersion = LevelDbMigrations::ReadSchemaVersion (_db.get ());
379+ XCTAssertEqual (finalVersion, latestVersion);
380+ }
381+
369382/* *
370383 * Creates the name of a dummy entry to make sure the iteration is correctly bounded.
371384 */
0 commit comments