Created
March 16, 2018 20:02
-
-
Save schmidt-sebastian/200629f197349de02a7ceea9d7242e39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=================================================================== | |
--- src/local/indexeddb_schema.ts (date 1521229071000) | |
+++ src/local/indexeddb_schema.ts (date 1521229071000) | |
@@ -26,51 +26,32 @@ | |
import { SnapshotVersion } from '../core/snapshot_version'; | |
/** | |
-<<<<<<< HEAD | |
- * Schema Version for the Web client (containing the Mutation Queue, the Query | |
- * and the Remote Document Cache) and Multi-Tab Support. | |
-======= | |
* Schema Version for the Web client: | |
* 1. Initial version including Mutation Queue, Query Cache, and Remote Document | |
* Cache | |
* 2. Added targetCount to targetGlobal row. | |
->>>>>>> master | |
+ * 3. Multi-Tab Support. | |
*/ | |
-export const SCHEMA_VERSION = 2; | |
+export const SCHEMA_VERSION = 3; | |
/** | |
* Performs database creation and schema upgrades. | |
* | |
* Note that in production, this method is only ever used to upgrade the schema | |
-<<<<<<< HEAD | |
* to SCHEMA_VERSION. Different versions are only used for testing and | |
* local feature development. | |
*/ | |
-export function createOrUpgradeDb( | |
- db: IDBDatabase, | |
- fromVersion: number, | |
- toVersion: number | |
-): void { | |
- // This function currently supports migrating to schema version 1 (Mutation | |
- // Queue, Query and Remote Document Cache) and schema version 2 (Multi-Tab). | |
-======= | |
- * to SCHEMA_VERSION. Different values of toVersion are only used for testing | |
- * and local feature development. | |
- */ | |
export function createOrUpgradeDb( | |
db: IDBDatabase, | |
txn: SimpleDbTransaction, | |
fromVersion: number, | |
toVersion: number | |
): PersistencePromise<void> { | |
- // This function currently supports migrating to schema version 1 (Mutation | |
- // Queue, Query and Remote Document Cache) and schema version 2 (Query | |
- // counting). | |
->>>>>>> master | |
assert( | |
- fromVersion < toVersion && fromVersion >= 0 && toVersion <= 2, | |
+ fromVersion < toVersion && fromVersion >= 0 && toVersion <= 3, | |
'Unexpected schema upgrade from v${fromVersion} to v{toVersion}.' | |
); | |
+ let p = PersistencePromise.resolve(); | |
if (fromVersion < 1 && toVersion >= 1) { | |
createOwnerStore(db); | |
@@ -79,20 +60,17 @@ | |
createRemoteDocumentCache(db); | |
} | |
-<<<<<<< HEAD | |
if (fromVersion < 2 && toVersion >= 2) { | |
+ p = ensureTargetGlobalExists(txn).next(targetGlobal => | |
+ saveTargetCount(txn, targetGlobal) | |
+ ); | |
+ } | |
+ | |
+ if (fromVersion < 3 && toVersion >= 3) { | |
createClientMetadataStore(db); | |
createTargetChangeStore(db); | |
} | |
-======= | |
- let p = PersistencePromise.resolve(); | |
- if (fromVersion < 2 && toVersion >= 2) { | |
- p = ensureTargetGlobalExists(txn).next(targetGlobal => | |
- saveTargetCount(txn, targetGlobal) | |
- ); | |
- } | |
return p; | |
->>>>>>> master | |
} | |
// TODO(mikelehen): Get rid of "as any" if/when TypeScript fixes their types. | |
@@ -535,46 +513,7 @@ | |
} | |
/** | |
-<<<<<<< HEAD | |
- * An object representing the changes at a particular snapshot version for the | |
- * given target. This is used to facilitate storing query changelogs in the | |
- * targetChanges object store. | |
- * | |
- * PORTING NOTE: This is used for change propagation during multi-tab syncing | |
- * and not needed on iOS and Android. | |
- */ | |
-export class DbTargetChange { | |
- /** Name of the IndexedDb object store. */ | |
- static store = 'targetChanges'; | |
- | |
- /** Keys are automatically assigned via the targetId and snapshotVersion. */ | |
- static keyPath = ['targetId', 'snapshotVersion']; | |
- | |
- constructor( | |
- /** | |
- * The targetId identifying a target. | |
- */ | |
- public targetId: TargetId, | |
- /** | |
- * The snapshot version for this change. | |
- */ | |
- public snapshotVersion: DbTimestamp, | |
- /** | |
- * The keys of the changed documents in this snapshot. | |
- */ | |
- public changes: { | |
- added?: EncodedResourcePath[]; | |
- modified?: EncodedResourcePath[]; | |
- removed?: EncodedResourcePath[]; | |
- } | |
- ) {} | |
-} | |
- | |
-function createTargetChangeStore(db: IDBDatabase): void { | |
- db.createObjectStore(DbTargetChange.store, { | |
- keyPath: DbTargetChange.keyPath as KeyPath | |
-======= | |
- * Counts the number of targets persisted and adds that value to the target | |
+ * * Counts the number of targets persisted and adds that value to the target | |
* global singleton. | |
*/ | |
function saveTargetCount( | |
@@ -615,21 +554,55 @@ | |
); | |
return globalStore.put(DbTargetGlobal.key, metadata).next(() => metadata); | |
} | |
->>>>>>> master | |
+ }); | |
+} | |
+ | |
+/** | |
+ * An object representing the changes at a particular snapshot version for the | |
+ * given target. This is used to facilitate storing query changelogs in the | |
+ * targetChanges object store. | |
+ * | |
+ * PORTING NOTE: This is used for change propagation during multi-tab syncing | |
+ * and not needed on iOS and Android. | |
+ */ | |
+export class DbTargetChange { | |
+ /** Name of the IndexedDb object store. */ | |
+ static store = 'targetChanges'; | |
+ | |
+ /** Keys are automatically assigned via the targetId and snapshotVersion. */ | |
+ static keyPath = ['targetId', 'snapshotVersion']; | |
+ | |
+ constructor( | |
+ /** | |
+ * The targetId identifying a target. | |
+ */ | |
+ public targetId: TargetId, | |
+ /** | |
+ * The snapshot version for this change. | |
+ */ | |
+ public snapshotVersion: DbTimestamp, | |
+ /** | |
+ * The keys of the changed documents in this snapshot. | |
+ */ | |
+ public changes: { | |
+ added?: EncodedResourcePath[]; | |
+ modified?: EncodedResourcePath[]; | |
+ removed?: EncodedResourcePath[]; | |
+ } | |
+ ) {} | |
+} | |
+ | |
+function createTargetChangeStore(db: IDBDatabase): void { | |
+ db.createObjectStore(DbTargetChange.store, { | |
+ keyPath: DbTargetChange.keyPath as KeyPath | |
}); | |
} | |
/** | |
-<<<<<<< HEAD | |
* A record of the metadata state of each client. | |
* | |
* PORTING NOTE: This is used to synchronize multi-tab state and does not need | |
* to be ported to iOS or Android. | |
-======= | |
- * The list of all default IndexedDB stores used throughout the SDK. This is | |
- * used when creating transactions so that access across all stores is done | |
- * atomically. | |
->>>>>>> master | |
*/ | |
export class DbClientMetadata { | |
/** Name of the IndexedDb object store. */ | |
@@ -669,11 +642,13 @@ | |
DbTargetDocument.store | |
]; | |
-const V2_STORES = [DbClientMetadata.store, DbTargetChange.store]; | |
+export const V2_STORES = V1_STORES; | |
+ | |
+const V3_STORES = [...V2_STORES, DbClientMetadata.store, DbTargetChange.store]; | |
/** | |
* The list of all default IndexedDB stores used throughout the SDK. This is | |
* used when creating transactions so that access across all stores is done | |
* atomically. | |
*/ | |
-export const ALL_STORES = [...V1_STORES, ...V2_STORES]; | |
+export const ALL_STORES = V3_STORES; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment