Advanced

Schema & Migrations

How to evolve your database schema over time with versioned upgrades.

Automatic schema management

svelte-idb automatically creates object stores and indexes based on your declarative schema. When you increment the version number and change the stores config, it applies the necessary changes during the onupgradeneeded event.

Adding a new store

migration-v2.ts

Adding indexes

migration-indexes.ts

Custom migrations

For complex migrations (data transforms, removing stores), use the onUpgrade callback.

custom-migration.ts