title: How do I get hold of both the old and new versions of the IndexedDB database, while catering for both setVersion and onUpgradeNeeded?
body: <p>There are already questions and answers like this</p>
  
  <p><a href="https://stackoverflow.com/questions/11532935/add-index-to-pre-existing-objectstore-in-indexeddb-using-javascript">Add Index to Pre-Existing ObjectStore In IndexedDB Using Javascript</a></p>
  
  <p>but I can't see how that code caters for incremental versions for BOTH the setVersion and onUpgradeNeeded methods. Something like the following pseudoCode..</p>
  
  <p><code><br>
  if (oldVersion &lt; 1)
  <br>createObjectStore
  <br>if (oldVersion &lt; 2)
  <br>createNewIndex
  <br> etc etc etc...
  </code></p>
  
  <p>I.e. I know how to get the oldVersion for the setVersion method (Check if db.serVersion  exists and then query the value of db.version), but I don't know how to get the old version for the newer onUpgradeNeeded method.</p>
  
  <p>It wasn't obvious from <a href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#request-api" rel="nofollow noreferrer">http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#request-api</a> either :-(</p>
  
  <p>THanx.</p>