Skip to content

Commit 016221d

Browse files
committed
Schema upgrade done right.
1 parent 39771c3 commit 016221d

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@ class SQLiteSchema {
4949
* The version of the schema. Increase this by one for each migration added to runMigrations
5050
* below.
5151
*/
52-
static final int VERSION = 12;
53-
54-
static final int OVERLAY_SUPPORT_VERSION = VERSION + 1;
52+
static final int VERSION = 13;
5553

5654
// TODO(indexing): Remove this constant and increment VERSION to enable indexing support
57-
static final int INDEXING_SUPPORT_VERSION = OVERLAY_SUPPORT_VERSION + 1;
55+
static final int INDEXING_SUPPORT_VERSION = VERSION + 1;
5856

5957
/**
6058
* The batch size for the sequence number migration in `ensureSequenceNumbers()`.
@@ -80,9 +78,6 @@ void runSchemaUpgrades() {
8078

8179
void runSchemaUpgrades(int fromVersion) {
8280
int toVersion = VERSION;
83-
if (Persistence.OVERLAY_SUPPORT_ENABLED) {
84-
toVersion = OVERLAY_SUPPORT_VERSION;
85-
}
8681
if (Persistence.INDEXING_SUPPORT_ENABLED) {
8782
toVersion = INDEXING_SUPPORT_VERSION;
8883
}
@@ -170,8 +165,17 @@ void runSchemaUpgrades(int fromVersion, int toVersion) {
170165
if (fromVersion < 12 && toVersion >= 12) {
171166
createBundleCache();
172167
}
168+
169+
if (fromVersion < 13 && toVersion >= 13) {
170+
Preconditions.checkState(
171+
Persistence.OVERLAY_SUPPORT_ENABLED || Persistence.INDEXING_SUPPORT_ENABLED);
172+
createOverlays();
173+
createDataMigrationTable();
174+
addPendingDataMigration(Persistence.DATA_MIGRATION_BUILD_OVERLAYS);
175+
}
176+
173177
/*
174-
* Adding a new migration? READ THIS FIRST!
178+
* Adding a new schema upgrade? READ THIS FIRST!
175179
*
176180
* Be aware that the SDK version may be downgraded then re-upgraded. This means that running
177181
* your new migration must not prevent older versions of the SDK from functioning. Additionally,
@@ -182,13 +186,6 @@ void runSchemaUpgrades(int fromVersion, int toVersion) {
182186
* maintained invariants from later versions, so migrations that update values cannot assume
183187
* that existing values have been properly maintained. Calculate them again, if applicable.
184188
*/
185-
if (fromVersion < OVERLAY_SUPPORT_VERSION && toVersion >= OVERLAY_SUPPORT_VERSION) {
186-
Preconditions.checkState(
187-
Persistence.OVERLAY_SUPPORT_ENABLED || Persistence.INDEXING_SUPPORT_ENABLED);
188-
createOverlays();
189-
createDataMigrationTable();
190-
addPendingDataMigration(Persistence.DATA_MIGRATION_BUILD_OVERLAYS);
191-
}
192189

193190
if (fromVersion < INDEXING_SUPPORT_VERSION && toVersion >= INDEXING_SUPPORT_VERSION) {
194191
Preconditions.checkState(Persistence.INDEXING_SUPPORT_ENABLED);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public class SQLiteOverlayMigrationManagerTest {
5151

5252
@Before
5353
public void setUp() {
54+
// Setup persistence to version 12, which is before Overlay.
5455
persistence =
55-
PersistenceTestHelpers.createSQLitePersistenceForVersion(
56-
"test-data-migration", SQLiteSchema.OVERLAY_SUPPORT_VERSION - 1);
56+
PersistenceTestHelpers.createSQLitePersistenceForVersion("test-data-migration", 12);
5757
IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
5858
localStore =
5959
new LocalStore(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ public void createsIndexingTables() {
638638

639639
@Test
640640
public void createsOverlaysAndMigrationTable() {
641-
schema.runSchemaUpgrades(0, SQLiteSchema.OVERLAY_SUPPORT_VERSION);
641+
// 13 is the version we enable Overlay
642+
schema.runSchemaUpgrades(0, 13);
642643
assertTableExists("document_overlays");
643644
assertTableExists("data_migrations");
644645

0 commit comments

Comments
 (0)