Indexddb twice open is suspended

problem description

I need to dynamically add the "table" (store), of indexddb to the project instead of initializing all the tables to be used at once. However, there is a problem when triggering the version update event, and the crux of the problem is as follows:

the code is as follows

const one = window.indexedDB.open("test");
one.onupgradeneeded = e => {
  console.log("db one upgrade success", e.target.readyState);
  updateDB();
}

function updateDB() {
  const tow = window.indexedDB.open("test", 2);
  tow.onupgradeneeded = e => {
    console.log("db tow upgrade success", e.target.readyState);
  }
  tow.onblocked = e => {
    console.log("blocked:", e)
  }

  setTimeout(() => {
    console.log(tow.readyState);
  }, 3000);
}

running results

questions

after creating the database, update the database version and expect some action in the upgradeneeded event, but the second operation is suspended and cannot trigger the upgradeneeded event. In fact, success and error are not triggered either. Could you tell me how to solve this situation?

Nov.29,2021

forgot to end the problem, and it was solved at that time, using the close () method to end the database connection, which was written in the comment on the question.
has been systematically studying indexedDB recently, and a lot of IndexedDB documents have been translated on MDN.
for details and principles of the above issues, see the MDN documentation.

to put it simply, when the same database under the same source is opened, the version upgrade is blocked, and the upgrade event will not continue until the close method is called to close the previous database connection.


A transaction has been opened after the visual indexedDB is opened. You cannot call open again in the upgradeneeded. This is a conflict between the two transactions.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36f42-2c04f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36f42-2c04f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?