@@ -22,16 +22,17 @@ import {
22
22
createOrUpgradeDb ,
23
23
DbMutationBatch ,
24
24
DbMutationBatchKey ,
25
- < << << << HEAD
26
25
DbOwner ,
27
26
DbOwnerKey ,
28
27
DbTarget ,
29
28
DbTargetGlobal ,
30
29
DbTargetGlobalKey ,
31
30
SCHEMA_VERSION ,
32
31
V1_STORES ,
33
- V2_STORES ,
34
- V3_STORES
32
+ V3_STORES ,
33
+ DbTargetKey ,
34
+ DbTimestamp ,
35
+ V4_STORES
35
36
} from '../../../src/local/indexeddb_schema' ;
36
37
import { SimpleDb , SimpleDbTransaction } from '../../../src/local/simple_db' ;
37
38
import { PersistencePromise } from '../../../src/local/persistence_promise' ;
@@ -41,16 +42,7 @@ import { JsonProtoSerializer } from '../../../src/remote/serializer';
41
42
import { PlatformSupport } from '../../../src/platform/platform' ;
42
43
import { AsyncQueue } from '../../../src/util/async_queue' ;
43
44
import { SharedFakeWebStorage , TestPlatform } from '../../util/test_platform' ;
44
- = === ===
45
- DbTarget ,
46
- DbTargetGlobal ,
47
- DbTargetGlobalKey ,
48
- DbTargetKey ,
49
- DbTimestamp
50
- } from '../../../src/local/indexeddb_schema' ;
51
- import { SimpleDb , SimpleDbTransaction } from '../../../src/local/simple_db' ;
52
45
import { SnapshotVersion } from '../../../src/core/snapshot_version' ;
53
- > >>> >>> master
54
46
55
47
const INDEXEDDB_TEST_DATABASE_PREFIX = 'schemaTest/' ;
56
48
const INDEXEDDB_TEST_DATABASE =
@@ -126,6 +118,17 @@ function getAllObjectStores(db: IDBDatabase): string[] {
126
118
return objectStores ;
127
119
}
128
120
121
+ function getTargetCount ( db : IDBDatabase ) : Promise < number > {
122
+ const sdb = new SimpleDb ( db ) ;
123
+ return sdb
124
+ . runTransaction ( 'readonly' , [ DbTargetGlobal . store ] , txn =>
125
+ txn
126
+ . store < DbTargetGlobalKey , DbTargetGlobal > ( DbTargetGlobal . store )
127
+ . get ( DbTargetGlobal . key )
128
+ )
129
+ . then ( metadata => metadata . targetCount ) ;
130
+ }
131
+
129
132
describe ( 'IndexedDbSchema: createOrUpgradeDb' , ( ) => {
130
133
if ( ! IndexedDbPersistence . isAvailable ( ) ) {
131
134
console . warn ( 'No IndexedDB. Skipping createOrUpgradeDb() tests.' ) ;
@@ -144,31 +147,19 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
144
147
} ) ;
145
148
} ) ;
146
149
147
- < < < << << HEAD
148
- it ( 'can install schema version 2' , ( ) => {
149
- return withDb ( 2 , db => {
150
- expect ( db . version ) . to . equal ( 2 ) ;
150
+ it ( 'can install schema version 3' , ( ) => {
151
+ return withDb ( 3 , db => {
152
+ expect ( db . version ) . to . equal ( 3 ) ;
151
153
// We should have all of the stores, we should have the target global row
152
154
// and we should not have any targets counted, because there are none.
153
- expect ( getAllObjectStores ( db ) ) . to . have . members ( V2_STORES ) ;
155
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( V3_STORES ) ;
154
156
// Check the target count. We haven't added any targets, so we expect 0.
155
157
return getTargetCount ( db ) . then ( targetCount => {
156
158
expect ( targetCount ) . to . equal ( 0 ) ;
157
159
} ) ;
158
160
} ) ;
159
161
} ) ;
160
162
161
- it ( 'can install schema version 3' , ( ) => {
162
- return withDb ( 3 , async db => {
163
- expect ( db . version ) . to . be . equal ( 3 ) ;
164
- expect ( getAllObjectStores ( db ) ) . to . have . members ( V3_STORES ) ;
165
- } ) ;
166
- } ) ;
167
-
168
- it ( 'can upgrade from schema version 1 to 2' , ( ) => {
169
- const expectedTargetCount = 5 ;
170
- return withDb ( 1 , db => {
171
- = === ===
172
163
it ( 'drops the query cache from 2 to 3' , ( ) => {
173
164
const userId = 'user' ;
174
165
const batchId = 1 ;
@@ -189,7 +180,6 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
189
180
) ;
190
181
191
182
return withDb ( 2 , db => {
192
- > >>> >>> master
193
183
const sdb = new SimpleDb ( db ) ;
194
184
return sdb . runTransaction (
195
185
'readwrite' ,
@@ -213,24 +203,11 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
213
203
. next ( ( ) => mutations . put ( expectedMutation ) )
214
204
) ;
215
205
}
216
- << < < < << HEAD
217
- return p ;
218
- } ) ;
219
- } ) . then ( ( ) =>
220
- withDb ( 2 , db => {
221
- expect ( db . version ) . to . equal ( 2 ) ;
222
- expect ( getAllObjectStores ( db ) ) . to . have . members ( V2_STORES ) ;
223
- return getTargetCount ( db ) . then ( targetCount => {
224
- expect ( targetCount ) . to . equal ( expectedTargetCount ) ;
225
- } ) ;
226
- } )
227
- ) ;
228
- = === ===
229
206
) ;
230
207
} ) . then ( ( ) => {
231
208
return withDb ( 3 , db => {
232
209
expect ( db . version ) . to . equal ( 3 ) ;
233
- expect ( getAllObjectStores ( db ) ) . to . have . members ( ALL_STORES ) ;
210
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( V3_STORES ) ;
234
211
235
212
const sdb = new SimpleDb ( db ) ;
236
213
return sdb . runTransaction (
@@ -259,7 +236,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
259
236
const expected = JSON . parse ( JSON . stringify ( resetTargetGlobal ) ) ;
260
237
expect ( targetGlobalEntry ) . to . deep . equal ( expected ) ;
261
238
} )
262
- . next ( ( ) => mutations . get ( [ userId , batchId ] ) )
239
+ . next ( ( ) => mutations . get ( batchId ) )
263
240
. next ( mutation => {
264
241
// Mutations should be unaffected.
265
242
expect ( mutation . userId ) . to . equal ( userId ) ;
@@ -269,10 +246,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
269
246
) ;
270
247
} ) ;
271
248
} ) ;
272
- > >>> >>> master
273
249
} ) ;
274
250
275
- it ( 'can upgrade from schema version 2 to 3 ' , ( ) => {
251
+ it ( 'can upgrade from schema version 3 to 4 ' , ( ) => {
276
252
const testWrite = { delete : 'foo' } ;
277
253
const testMutations = [
278
254
{
@@ -295,7 +271,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
295
271
}
296
272
] ;
297
273
298
- return withDb ( 2 , db => {
274
+ return withDb ( 3 , db => {
299
275
const sdb = new SimpleDb ( db ) ;
300
276
return sdb . runTransaction ( 'readwrite' , [ DbMutationBatch . store ] , txn => {
301
277
const store = txn . store ( DbMutationBatch . store ) ;
@@ -306,9 +282,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
306
282
return p ;
307
283
} ) ;
308
284
} ) . then ( ( ) =>
309
- withDb ( 3 , db => {
310
- expect ( db . version ) . to . be . equal ( 3 ) ;
311
- expect ( getAllObjectStores ( db ) ) . to . have . members ( V3_STORES ) ;
285
+ withDb ( 4 , db => {
286
+ expect ( db . version ) . to . be . equal ( 4 ) ;
287
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( V4_STORES ) ;
312
288
313
289
const sdb = new SimpleDb ( db ) ;
314
290
return sdb . runTransaction ( 'readwrite' , [ DbMutationBatch . store ] , txn => {
0 commit comments