5.7. Running an upgrade transaction

To run an upgrade transaction with a connection object which is used to update the database, a new version to be set for the database, and a request, run these steps:

  1. Let db be connection’s database.

  2. Let transaction be a new upgrade transaction with connection used as connection. The scope of transaction includes every object store in connection.

  3. Set database’s upgrade transaction to transaction.

  4. Set transaction’s state to inactive.

  5. Start transaction.

    Note that until this transaction is finished, no other connections can be opened to the same database.

  6. Let old version be db’s version.

  7. Set db’s version to version. This change is considered part of the transaction, and so if the transaction is aborted, this change is reverted.

  8. Set request’s processed flag to true.

  9. Queue a task to run these steps:

    1. Set request’s result to connection.

    2. Set request’s transaction to transaction.

    3. Set request’s done flag to true.

    4. Set transaction’s state to active.

    5. Let didThrow be the result of running fire a version change event named upgradeneeded at request with old version and version.

    6. Set transaction’s state to inactive.

    7. If didThrow is true, run abort a transaction with the error property set to a newly created[AbortError](https://heycam.github.io/webidl/#aborterror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  10. Wait for transaction to finish.

    Some of the algorithms invoked during the transaction‘s lifetime, such as the steps to commit a transaction and the steps to abort a transaction, include steps specific to upgrade transactions.