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:
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.
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 db’s version to version. This change is considered part of the transaction, and so if the transaction is aborted, this change is reverted.
Set request’s processed flag to true.
Queue a task to run these steps:
Set request’s result to connection.
Set request’s transaction to transaction.
Set request’s done flag to true.
Let didThrow be the result of running fire a version change event named
upgradeneeded
at request with old version and version.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)
.
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.