Versioning the Database
Explore how to effectively manage database versioning in IndexedDB. Learn to create and upgrade object stores when updating web applications, handle version changes properly, and understand resulting event flows. This lesson helps you build scalable client-side storage that adapts as your app evolves.
Versioning the database of IndexedDB
IndexedDB is a client-side database, and developers don’t have full-time control over it.
For example, consider a scenario where we update the database version to 2 while a user is still using our web app with a version 1 database. The user won’t be notified until and unless the page is refreshed.
Example
Our web app currently uses version 1 of the School database. When a user visits our web app for the first time, our code tries to open the School database with version 1. If the School database isn’t present in the user’s browser, a new database is created with version 1.
Let’s write the code to demonstrate the scenario above:
Line 1: We try to open the
Schooldatabase ...