diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d84085..2d387be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.4.4 * Add another example, showing how to build repositories with a `Future>` interface +* Fix index migration bug (introduced in 1.4.3), when a name is reused across index versions ## 1.4.3 diff --git a/lib/src/index_entity_store.dart b/lib/src/index_entity_store.dart index 5d0cde5..2fa65b7 100644 --- a/lib/src/index_entity_store.dart +++ b/lib/src/index_entity_store.dart @@ -383,6 +383,11 @@ class IndexedEntityStore { _database.execute('BEGIN'); + _database.execute( + 'DELETE FROM `index` WHERE `type` = ?', + [_entityKey], + ); + final entities = getAllOnce(); for (final e in entities) { diff --git a/test/indexed_entity_store_test.dart b/test/indexed_entity_store_test.dart index b7dab2a..402b211 100644 --- a/test/indexed_entity_store_test.dart +++ b/test/indexed_entity_store_test.dart @@ -135,7 +135,7 @@ void main() { { final db = IndexedEntityDabase.open(path); - final fooStore = db.entityStore(fooConnectorWithIndexOnC); + final fooStore = db.entityStore(fooConnectorWithIndexOnBAndC); expect(fooStore.getAllOnce(), hasLength(1)); // old index is not longer supported @@ -143,6 +143,10 @@ void main() { () => fooStore.queryOnce((cols) => cols['a'].equals('A')), throwsException, ); + expect( + fooStore.queryOnce((cols) => cols['b'].equals(1002)), + hasLength(1), + ); expect( fooStore.queryOnce((cols) => cols['c'].equals(true)), hasLength(1), @@ -1101,11 +1105,12 @@ final fooConnector = IndexedEntityConnector<_FooEntity, int, String>( ), ); -final fooConnectorWithIndexOnC = +final fooConnectorWithIndexOnBAndC = IndexedEntityConnector<_FooEntity, int, String>( entityKey: fooConnector.entityKey, getPrimaryKey: fooConnector.getPrimaryKey, getIndices: (index) { + index((e) => e.valueB + 1000, as: 'b'); // updated index B index((e) => e.valueC, as: 'c'); }, serialize: fooConnector.serialize,