es2015/migration/DatabaseMigrator.js
function migrateDatabase(nativeDatabase, nativeTransaction, schemaDescriptors,
    currentVersion) {
  let descriptorsToProcess = schemaDescriptors.filter((descriptor) => {
    return descriptor.version > currentVersion
  })
  
  if (!descriptorsToProcess.length) {
    return PromiseSync.resolve(undefined)
  }
  
  return migrateDatabaseVersion(
    nativeDatabase,
    nativeTransaction,
    descriptorsToProcess[0]
  ).then(() => {
    return migrateDatabase(
      nativeDatabase,
      nativeTransaction,
      descriptorsToProcess,
      descriptorsToProcess[0].version
    )
  })
}
function migrateDatabase(nativeDatabase, nativeTransaction, schemaDescriptors,
    currentVersion) {
  let descriptorsToProcess = schemaDescriptors.filter((descriptor) => {
    return descriptor.version > currentVersion
  })
  
  if (!descriptorsToProcess.length) {
    return PromiseSync.resolve(undefined)
  }
  
  return migrateDatabaseVersion(
    nativeDatabase,
    nativeTransaction,
    descriptorsToProcess[0]
  ).then(() => {
    return migrateDatabase(
      nativeDatabase,
      nativeTransaction,
      descriptorsToProcess,
      descriptorsToProcess[0].version
    )
  })
}
function migrateDatabase ( nativeDatabase , nativeTransaction , schemaDescriptors , currentVersion ) { let descriptorsToProcess = schemaDescriptors . filter ( ( descriptor ) => { return descriptor . version > currentVersion } ) if ( ! descriptorsToProcess . length ) { return PromiseSync . resolve ( undefined ) } return migrateDatabaseVersion ( nativeDatabase , nativeTransaction , descriptorsToProcess [ 0 ] ) . then ( ( ) => { return migrateDatabase ( nativeDatabase , nativeTransaction , descriptorsToProcess , descriptorsToProcess [ 0 ] . version ) } ) }
Processes the schema descriptors to upgrade the database schema to the
greatest version specified.

@param {IDBDatabase} nativeDatabase The native Indexed DB database being
migrated to a higher version.
@param {IDBTransaction} nativeTransaction The native Indexed DB
{@code versionchange} transaction to use to manipulate the data.
@param {(DatabaseSchema|UpgradedDatabaseSchema)[]} schemaDescriptors Schema
descriptors of the database schemas for various versions, sorted in
ascending order by the version number.
@param {number} currentVersion The current version of the database schema.
@return {PromiseSync<undefined>} A promise that resolves when the schema is
upgraded to the greatest version specified in the schema
descriptors.
Processes the schema descriptors to upgrade the database schema to the greatest version specified .