5.7. Running an upgrade transaction

The steps to run an upgrade transaction are as follows. This algorithm takes three arguments: a connection object which is used to update the database, a new version to be set for the database, and a request.

  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. Unset transaction’s active flag.

  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 the version of db to version. This change is considered part of the transaction, and so if the transaction is aborted, this change is reverted.

  8. Queue a task to run these steps:

    1. Set request’s result to connection.

    2. Set request’s transaction to transaction.

    3. Set the done flag on the request.

    4. Set transaction’s active flag.

    5. Let didThrow be the result of running the steps to fire a version change event named [upgradeneeded](#request-upgradeneeded) at request with old version and version.

    6. Unset transaction’s active flag.

    7. If didThrow is set, run the steps to abort a transaction with the error property set to a newly created[AbortError](https://www.w3.org/TR/WebIDL-1/#aborterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  9. 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.