Skip to content

Commit

Permalink
Fix index migration bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tp committed Nov 4, 2024
1 parent ec80b3a commit 889f01f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.4.4

* Add another example, showing how to build repositories with a `Future<ValueListenable<T>>` interface
* Fix index migration bug (introduced in 1.4.3), when a name is reused across index versions

## 1.4.3

Expand Down
5 changes: 5 additions & 0 deletions lib/src/index_entity_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ class IndexedEntityStore<T, K> {

_database.execute('BEGIN');

_database.execute(
'DELETE FROM `index` WHERE `type` = ?',
[_entityKey],
);

final entities = getAllOnce();

for (final e in entities) {
Expand Down
9 changes: 7 additions & 2 deletions test/indexed_entity_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,18 @@ 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
expect(
() => 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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 889f01f

Please sign in to comment.