ReviewOS

stacks/bun-query-builder

Refactor: dedupe relation-normalization logic (meta.ts vs migrations.ts)

#1042
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days ago

Summary

meta.ts (toRecord/toBelongsToManyRecord) and migrations.ts (normalizeBelongsTo) independently re-implement "unwrap string | { model } | array | record" for relation entries. This is the exact shape that caused #1023, and the fix had to be applied in two places; they've already diverged (meta handles all relation kinds, migrations only belongsTo), so the next such bug will likely be fixed in only one.

Suggested fix

Extract a single normalizeRelationEntry(entry): { model, foreignKey?, onDelete? } | null (+ toModelRecord) into a shared module and consume from both.

Severity: low/medium (maintainability). Found via internal code audit.

Sign in to comment on this issue.