Skip to content

Commit 9e4e0fc

Browse files
Copilotdevlux76
andcommitted
fix(P0-X): drop migration cruft from applyUpgrade — no installed base
Remove the cursor-based metroid_neighbors → neighbor_graph migration from the v3 upgrade path. The project has no installed base, so the migration is unnecessary overhead. applyUpgrade simply creates neighbor_graph fresh. Also reverts open() back to the simpler single-argument applyUpgrade(db) call. Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
1 parent 75fe21c commit 9e4e0fc

1 file changed

Lines changed: 3 additions & 24 deletions

File tree

storage/IndexedDbMetadataStore.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function promisifyTransaction(tx: IDBTransaction): Promise<void> {
5050
// Schema upgrade
5151
// ---------------------------------------------------------------------------
5252

53-
function applyUpgrade(db: IDBDatabase, upgradeTx: IDBTransaction): void {
53+
function applyUpgrade(db: IDBDatabase): void {
5454
// v1 stores
5555
if (!db.objectStoreNames.contains(STORE.pages)) {
5656
db.createObjectStore(STORE.pages, { keyPath: "pageId" });
@@ -95,29 +95,10 @@ function applyUpgrade(db: IDBDatabase, upgradeTx: IDBTransaction): void {
9595
db.createObjectStore(STORE.pageActivity, { keyPath: "pageId" });
9696
}
9797

98-
// v3 stores — rename metroid_neighbors → neighbor_graph
98+
// v3 stores — neighbor_graph (replaces the old metroid_neighbors name)
9999
if (!db.objectStoreNames.contains(STORE.neighborGraph)) {
100100
db.createObjectStore(STORE.neighborGraph, { keyPath: "pageId" });
101101
}
102-
if (db.objectStoreNames.contains("metroid_neighbors")) {
103-
// Copy all records from the old store to the new one via an IDB cursor.
104-
// Each cursor.continue() call keeps the upgrade transaction alive; the
105-
// transaction cannot commit until the cursor is exhausted (cursor === null).
106-
// deleteObjectStore is invoked only once, in the final else-branch, after
107-
// every record has been migrated.
108-
const oldStore = upgradeTx.objectStore("metroid_neighbors");
109-
const newStore = upgradeTx.objectStore(STORE.neighborGraph);
110-
oldStore.openCursor().onsuccess = (event) => {
111-
const cursor = (event.target as IDBRequest<IDBCursorWithValue | null>).result;
112-
if (cursor) {
113-
newStore.put(cursor.value);
114-
cursor.continue();
115-
} else {
116-
// cursor is null — all records migrated; safe to drop the old store now.
117-
db.deleteObjectStore("metroid_neighbors");
118-
}
119-
};
120-
}
121102
}
122103

123104
// ---------------------------------------------------------------------------
@@ -146,9 +127,7 @@ export class IndexedDbMetadataStore implements MetadataStore {
146127
const req = indexedDB.open(dbName, DB_VERSION);
147128

148129
req.onupgradeneeded = (event) => {
149-
const db = (event.target as IDBOpenDBRequest).result;
150-
const tx = (event.target as IDBOpenDBRequest).transaction!;
151-
applyUpgrade(db, tx);
130+
applyUpgrade((event.target as IDBOpenDBRequest).result);
152131
};
153132

154133
req.onsuccess = () => resolve(new IndexedDbMetadataStore(req.result));

0 commit comments

Comments
 (0)