-
Notifications
You must be signed in to change notification settings - Fork 930
Add a schema migration that drops the query cache #1019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,12 @@ import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence'; | |
import { | ||
ALL_STORES, | ||
createOrUpgradeDb, | ||
DbMutationBatch, | ||
DbMutationBatchKey, | ||
DbTarget, | ||
DbTargetGlobal, | ||
DbTargetGlobalKey | ||
DbTargetGlobalKey, | ||
DbTargetKey | ||
} from '../../../src/local/indexeddb_schema'; | ||
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db'; | ||
import { PersistencePromise } from '../../../src/local/persistence_promise'; | ||
|
@@ -135,4 +138,63 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => { | |
}) | ||
); | ||
}); | ||
|
||
it('drops the query cache from 2 to 3', () => { | ||
const userId = 'user'; | ||
const batchId = 1; | ||
const targetId = 2; | ||
|
||
const expectedMutation = new DbMutationBatch(userId, batchId, 1000, []); | ||
|
||
return withDb(2, db => { | ||
const sdb = new SimpleDb(db); | ||
return sdb.runTransaction( | ||
'readwrite', | ||
[DbTarget.store, DbMutationBatch.store], | ||
txn => { | ||
const targets = txn.store<DbTargetKey, DbTarget>(DbTarget.store); | ||
const mutations = txn.store<DbMutationBatchKey, DbMutationBatch>( | ||
DbMutationBatch.store | ||
); | ||
|
||
return PersistencePromise.resolve().next(() => | ||
targets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just do:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
// tslint:disable-next-line:no-any | ||
.put({ targetId, canonicalId: 'foo' } as any) | ||
.next(() => mutations.put(expectedMutation)) | ||
); | ||
} | ||
); | ||
}).then(() => { | ||
return withDb(3, db => { | ||
expect(db.version).to.equal(3); | ||
expect(getAllObjectStores(db)).to.have.members(ALL_STORES); | ||
|
||
const sdb = new SimpleDb(db); | ||
return sdb.runTransaction( | ||
'readwrite', | ||
[DbTarget.store, DbMutationBatch.store], | ||
txn => { | ||
const targets = txn.store<DbTargetKey, DbTarget>(DbTarget.store); | ||
const mutations = txn.store<DbMutationBatchKey, DbMutationBatch>( | ||
DbMutationBatch.store | ||
); | ||
|
||
return PersistencePromise.resolve() | ||
.next(() => targets.get(targetId)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per Sebastian's comment above, you could do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
.next(target => { | ||
// The target should have been dropped | ||
expect(target).to.be.null; | ||
}) | ||
.next(() => mutations.get([userId, batchId])) | ||
.next(mutation => { | ||
// Mutations should be unaffected. | ||
expect(mutation.userId).to.equal(userId); | ||
expect(mutation.batchId).to.equal(batchId); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should wait for
p
(or get rid of the target count migration) before you continue with the migration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.