Skip to content

Commit 7926a0a

Browse files
authored
Actually skips overlay migration when run a second time. (#3704)
* Feedback. * Fix change log
1 parent 8394f24 commit 7926a0a

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

firebase-firestore/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ by opting into a release at
33
[go/firebase-android-release](http:go/firebase-android-release) (Googlers only).
44

55
# Unreleased
6-
- [changed] Added `TransactionOptions` to control how many times a transaction
6+
7+
# 24.1.2
8+
- [feature] Added `TransactionOptions` to control how many times a transaction
79
will retry commits before failing.
810
- [fixed] Fixed an issue where patching multiple fields shadows each other (#3528).
911

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteOverlayMigrationManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ private void buildOverlays() {
4646
db.runTransaction(
4747
"build overlays",
4848
() -> {
49+
if (!hasPendingOverlayMigration()) {
50+
return;
51+
}
52+
4953
Set<String> userIds = getAllUserIds();
5054
RemoteDocumentCache remoteDocumentCache = db.getRemoteDocumentCache();
5155
for (String uid : userIds) {

firebase-firestore/src/test/java/com/google/firebase/firestore/local/SQLiteOverlayMigrationManagerTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static java.util.Arrays.asList;
2626
import static org.junit.Assert.assertEquals;
2727
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertNull;
2829

2930
import com.google.firebase.firestore.FieldValue;
3031
import com.google.firebase.firestore.auth.User;
@@ -110,6 +111,46 @@ public void testCreateOverlayFromSet() {
110111
assertFalse(migrationManager.hasPendingOverlayMigration());
111112
}
112113

114+
@Test
115+
public void testSkipsIfAlreadyMigrated() {
116+
writeRemoteDocument(doc("foo/bar", 2, map("it", "original")));
117+
writeMutation(setMutation("foo/bar", map("foo", "bar")));
118+
119+
// Switch to new persistence and run migrations
120+
this.persistence.shutdown();
121+
persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration");
122+
IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
123+
localStore =
124+
new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED);
125+
localStore.start();
126+
127+
assertEquals(
128+
setMutation("foo/bar", map("foo", "bar")),
129+
persistence
130+
.getDocumentOverlayCache(User.UNAUTHENTICATED)
131+
.getOverlay(key("foo/bar"))
132+
.getMutation());
133+
134+
// Delete the overlay to verify migration is skipped the second time.
135+
persistence.getDocumentOverlayCache(User.UNAUTHENTICATED).removeOverlaysForBatchId(1);
136+
137+
// Switch to new persistence and run migrations which should be a no-op.
138+
this.persistence.shutdown();
139+
persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration");
140+
indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
141+
localStore =
142+
new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED);
143+
localStore.start();
144+
145+
SQLiteOverlayMigrationManager migrationManager =
146+
(SQLiteOverlayMigrationManager) persistence.getOverlayMigrationManager();
147+
assertFalse(migrationManager.hasPendingOverlayMigration());
148+
149+
// We deleted the overlay earlier and the migration is not run again, so we get a null.
150+
assertNull(
151+
persistence.getDocumentOverlayCache(User.UNAUTHENTICATED).getOverlay(key("foo/bar")));
152+
}
153+
113154
@Test
114155
public void testCreateOverlayFromDelete() {
115156
writeRemoteDocument(doc("foo/bar", 2, map("it", "original")));

0 commit comments

Comments
 (0)