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.
Let db be connection’s database.
Let transaction be a new upgrade transaction with connection used as connection. The scope of transaction includes every object store in connection.
Set database’s upgrade transaction to transaction.
Unset transaction’s active flag.
Start transaction.
Note that until this transaction is finished, no other connections can be opened to the same database.
Let old version be db’s version.
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.
Queue a task to run these steps:
Set request’s result to connection.
Set request’s transaction to transaction.
Set transaction’s active flag.
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.Unset transaction’s active flag.
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)
.
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.