Skip to content

Commit

Permalink
Resolving issue #612
Browse files Browse the repository at this point in the history
Calling upgrader the same way as it is done in transaction scope
  • Loading branch information
dfahlander committed Nov 12, 2018
1 parent 08ec72b commit 8070a6d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/classes/version/schema-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DbSchema } from '../../public/types/db-schema';
import { setProp, keys, slice, _global, isArray, shallowClone } from '../../functions/utils';
import { Transaction } from '../transaction';
import { Version } from './version';
import Promise, { PSD, newScope } from '../../helpers/promise';
import Promise, { PSD, newScope, NativePromise, decrementExpectedAwaits, AsyncFunction, incrementExpectedAwaits } from '../../helpers/promise';
import { exceptions } from '../../errors';
import { TableSchema } from '../../public/types/table-schema';
import { IndexSpec } from '../../public/types/index-spec';
Expand Down Expand Up @@ -138,9 +138,23 @@ export function updateTablesAndIndexes(
setApiOnPlace(db, [db.Transaction.prototype], keys(upgradeSchema), upgradeSchema);
trans.schema = upgradeSchema;

return Promise.follow(() => {
contentUpgrade(trans);
// Support for native async await.
if (contentUpgrade.constructor === AsyncFunction) {
incrementExpectedAwaits();
}
let returnValue: any;
const promiseFollowed = Promise.follow(() => {
// Finally, call the scope function with our table and transaction arguments.
returnValue = contentUpgrade(trans);
if (returnValue) {
if (returnValue.constructor === NativePromise) {
var decrementor = decrementExpectedAwaits.bind(null, null);
returnValue.then(decrementor, decrementor);
}
}
});
return (returnValue && typeof returnValue.then === 'function' ?
Promise.resolve(returnValue) : promiseFollowed.then(()=>returnValue));
}
});
queue.push(idbtrans => {
Expand Down

0 comments on commit 8070a6d

Please sign in to comment.