Skip to content

Commit 568f3ea

Browse files
kriszypclaude
andcommitted
fix(databases): address PR review — use attribute.attribute and fix removal test
- resources/databases.ts: use `attribute.attribute` instead of `attribute.name` in the non-indexed attribute findIndex (per cb1kenobi's suggestion; `attribute.name` can be falsey for attributes that arrive with only the `attribute` field set). - unitTests/resources/schemaMigrationFragility.test.js: fix removal regression test — after `table()` updates in-memory Table.attributes, re-create the stale main-thread state (still holding breed/age) before calling resetDatabases(), so the removal loop in initStores() is actually exercised. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8ccf8d6 commit 568f3ea

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

resources/databases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ function initStores(
626626
// hot-reload / worker restart. Without this, resetDatabases() re-reads these attributes
627627
// from attributesDbi but never merges them back into table.attributes — causing stale
628628
// schema metadata until a full kill+restart. (RE-7)
629-
const existingIdx = existingAttributes.findIndex((ea) => ea.name === attribute.name);
629+
const existingIdx = existingAttributes.findIndex((ea) => ea.name === attribute.attribute);
630630
if (existingIdx >= 0) {
631631
existingAttributes.splice(existingIdx, 1, attribute);
632632
} else {

unitTests/resources/schemaMigrationFragility.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,17 @@ describe('schema-migration fragility: non-indexed attributes missing from table.
455455
{ name: 'name' },
456456
],
457457
});
458+
// table() updates in-memory Table.attributes directly (databases.ts:997), so after the
459+
// call above the in-memory state is already [id, name]. Re-create the stale main-thread
460+
// view — still holding the old [id, name, breed, age] — so that the removal loop in
461+
// initStores() actually needs to drop breed and age.
462+
const tblForRemoval = getDatabases()[DB]?.[TABLE];
463+
tblForRemoval.attributes.splice(0, tblForRemoval.attributes.length,
464+
{ name: 'id', isPrimaryKey: true },
465+
{ name: 'name' },
466+
{ name: 'breed' },
467+
{ name: 'age' },
468+
);
458469
resetDatabases();
459470
const tbl = getDatabases()[DB]?.[TABLE];
460471
const attrNames = tbl.attributes.map((a) => a.name);

0 commit comments

Comments
 (0)