refactor(db): boolean mode for 0|1 flag columns#130
Merged
Conversation
Switches `isPublic`, `isDefault`, `isVolume`, `failureFlag`, `batchLookups`,
and `modelFallback` to `integer(..., { mode: 'boolean' })`. The on-disk
representation stays as INTEGER 0/1 — this is purely a TS-layer codec.
Side effect: `{flag && <X/>}` short-circuits to `false` (which React skips)
instead of rendering the literal `0`. Prevents the whole class of bugs that
hit `recipe.isPublic` in #129.
Call sites updated: writes pass true/false directly (no more `? 1 : 0`),
reads compare against booleans, and the API layer drops its `Boolean(...)`
coercion wrappers since the column already returns boolean.
The generated migration is a no-op (`SELECT 1`) — Drizzle wants to recreate
five tables to refresh the schema string, but the actual SQLite column type
is unchanged, so production data needs no rewrite.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Preview deployment
|
Zod schemas (`z.boolean()` / `z.boolean().optional()`) already narrow these inputs to `boolean | undefined` before they reach the handlers, so the `!!` and `=== true` coercions added in c3abc1b were noise. - workouts/addSet: `failureFlag: !!input.failureFlag` → pass through - ingredients/createUnit: same for `isDefault` - ingredients/updateUnit: drop the explicit `isDefault` override; just spread `updates` (the inner `if (updates.isDefault)` already clears siblings) - WorkoutSessionPage optimistic update: pass `variables.failureFlag` directly - SetRow: `failureFlag === true` → `failureFlag` (null/undefined fall through as falsy, which is what JSX wants anyway) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #129. Switches every
0|1integer flag in the schema to Drizzle'sinteger(..., { mode: 'boolean' }):recipes.isPublicingredientUnits.isDefaultusdaPortions.isVolumeworkoutLogs.failureFlaguserSettings.batchLookupsuserSettings.modelFallbackThe on-disk representation is unchanged (still
INTEGER 0/1) — this is purely a TS-layer codec. Drizzle reads0→falseand1→trueand serializes the other way around.Why: with these as plain
number,{flag && <X/>}in JSX leaked the literal0(the bug fixed forisPublicin #129). Withboolean, the same expression short-circuits tofalseand React renders nothing. Catches the whole class instead of one site at a time.Call sites updated:
true/falsedirectly — no moreflag ? 1 : 0rituals.Boolean(...)wrappers since the column already returns boolean.SetRow.failureFlagprop retypednumber | null→boolean | null;failureFlag === 1→failureFlag === true.parseIngredientListsignature retyped forisDefault.Migration
The generated migration is a no-op (
SELECT 1). Drizzle wants to recreate five tables to refresh the schema string, but the actual SQLite column type is unchanged, so production data needs no rewrite. The journal entry is preserved so future migrations stay in order.Test plan
yarn checkpasses🤖 Generated with Claude Code