Reference
Compressed map of connection lifecycle and schema changes. Pair with Lesson 2.
const request = indexedDB.open("app-db", 2); // name, version
request.onerror = (e) => { /* open failed */ };
request.onblocked = () => { /* other connections won’t close */ };
request.onupgradeneeded = (e) => {
const db = request.result;
const oldVersion = e.oldVersion; // 0 if brand new
// createObjectStore / createIndex / delete… only here
};
request.onsuccess = () => {
const db = request.result;
// use db.transaction(...) for reads/writes
};
| Style | Create | Put shape |
|---|---|---|
| In-line key | { keyPath: "id" } |
Key lives on the value object |
| Out-of-line key | no keyPath | Pass key as second arg to put/add |
| Generator | { autoIncrement: true } |
Optional keyPath that receives generated number |
versionchange.
db.close() (or reload).
blocked until they close.
upgradeneeded run for Tab B.
Schema lives in the upgrade path. Bumping version is a deploy concern
(old tabs, migration code, forever-forward oldVersion
steps) — not a free refactor.