IT-Hardware & Networking
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Schema migrations in IndexedDB are handled using the
onupgradeneededevent, which is triggered only when the database version number increases.This is how you can safely update the schema (e.g., add a new field, index, or object store) without losing existing data.
What Triggers a Migration?
When the version number changes:
onupgradeneededevent fires.Example: Add New Object Store & Index
Upgrade from version 1 → 2
Important: Existing Data Is Preserved
IndexedDB doesn't delete any data by default during upgrades.
If you change a keyPath or structure, you may need to:
Example: Manual Data Migration
Suppose you need to convert an old store to a new structure:
Avoid Common Mistakes
createObjectStore()twiceonblockedeventBest Practices for Migrations
if (oldVersion < X))onblockedandonerrorSummary
onupgradeneeded.onblocked,onerror, and version checks.