@@ -33,22 +33,23 @@ import { SimpleDbSchemaConverter, SimpleDbTransaction } from './simple_db';
33
33
34
34
/**
35
35
* Schema Version for the Web client:
36
- * 1. Initial version including Mutation Queue, Query Cache, and Remote Document
37
- * Cache
38
- * 2. Used to ensure a targetGlobal object exists and add targetCount to it. No
39
- * longer required because migration 3 unconditionally clears it.
40
- * 3. Dropped and re-created Query Cache to deal with cache corruption related
41
- * to limbo resolution. Addresses
42
- * https://github.com/firebase/firebase-ios-sdk/issues/1548
43
- * 4. Multi-Tab Support.
44
- * 5. Removal of held write acks.
45
- * 6. Create document global for tracking document cache size.
46
- * 7. Ensure every cached document has a sentinel row with a sequence number.
47
- * 8. Add collection-parent index for Collection Group queries.
48
- * 9. Change RemoteDocumentChanges store to be keyed by readTime rather than
49
- * an auto-incrementing ID. This is required for Index-Free queries.
36
+ * 1. Initial version including Mutation Queue, Query Cache, and Remote
37
+ * Document Cache
38
+ * 2. Used to ensure a targetGlobal object exists and add targetCount to it. No
39
+ * longer required because migration 3 unconditionally clears it.
40
+ * 3. Dropped and re-created Query Cache to deal with cache corruption related
41
+ * to limbo resolution. Addresses
42
+ * https://github.com/firebase/firebase-ios-sdk/issues/1548
43
+ * 4. Multi-Tab Support.
44
+ * 5. Removal of held write acks.
45
+ * 6. Create document global for tracking document cache size.
46
+ * 7. Ensure every cached document has a sentinel row with a sequence number.
47
+ * 8. Add collection-parent index for Collection Group queries.
48
+ * 9. Change RemoteDocumentChanges store to be keyed by readTime rather than
49
+ * an auto-incrementing ID. This is required for Index-Free queries.
50
+ * 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
50
51
*/
51
- export const SCHEMA_VERSION = 9 ;
52
+ export const SCHEMA_VERSION = 10 ;
52
53
53
54
/** Performs database creation and schema upgrades. */
54
55
export class SchemaConverter implements SimpleDbSchemaConverter {
@@ -71,7 +72,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
71
72
fromVersion < toVersion &&
72
73
fromVersion >= 0 &&
73
74
toVersion <= SCHEMA_VERSION ,
74
- `Unexpected schema upgrade from v${ fromVersion } to v{toVersion}.`
75
+ `Unexpected schema upgrade from v${ fromVersion } to v$ {toVersion } .`
75
76
) ;
76
77
77
78
const simpleDbTransaction = new SimpleDbTransaction ( txn ) ;
@@ -145,6 +146,10 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
145
146
createRemoteDocumentReadTimeIndex ( txn ) ;
146
147
} ) ;
147
148
}
149
+
150
+ if ( fromVersion < 10 && toVersion >= 10 ) {
151
+ p = p . next ( ( ) => this . rewriteCanonicalIds ( simpleDbTransaction ) ) ;
152
+ }
148
153
return p ;
149
154
}
150
155
@@ -299,6 +304,21 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
299
304
} ) ;
300
305
} ) ;
301
306
}
307
+
308
+ private rewriteCanonicalIds (
309
+ txn : SimpleDbTransaction
310
+ ) : PersistencePromise < void > {
311
+ const targetStore = txn . store < DbTargetKey , DbTarget > ( DbTarget . store ) ;
312
+
313
+ const persistencePromises : Array < PersistencePromise < void > > = [ ] ;
314
+ targetStore . iterate ( ( key , value ) => {
315
+ const originalTargetData = this . serializer . fromDbTarget ( value ) ;
316
+ const updatedTargetData = this . serializer . toDbTarget ( originalTargetData ) ;
317
+ persistencePromises . push ( targetStore . put ( updatedTargetData ) ) ;
318
+ } ) ;
319
+
320
+ return PersistencePromise . waitFor ( persistencePromises ) ;
321
+ }
302
322
}
303
323
304
324
function sentinelKey ( path : ResourcePath ) : DbTargetDocumentKey {
@@ -1079,6 +1099,8 @@ export const V8_STORES = [...V6_STORES, DbCollectionParent.store];
1079
1099
1080
1100
// V9 does not change the set of stores.
1081
1101
1102
+ // V10 does not change the set of stores.
1103
+
1082
1104
/**
1083
1105
* The list of all default IndexedDB stores used throughout the SDK. This is
1084
1106
* used when creating transactions so that access across all stores is done
0 commit comments