From ff3314ddb7587b26db1c6b9ec0acd0cd341858eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 14 May 2026 19:34:23 +0200 Subject: [PATCH] feat(db): add user.onboardingStep for wizard resume-state Persists the highest step a user reached in the rebuilt /onboarding flow so closing the tab mid-flow no longer wipes progress. Nullable Int default 0; encoding mirrors the new wizard: 0 welcome / 1 goals / 2 source / 3 baseline / 4 done Migration is idempotent (ADD COLUMN IF NOT EXISTS) so it tolerates hand-applied dev-DB state without diverging from the migration history. --- .../0057_user_onboarding_step/migration.sql | 26 +++++++++++++++++++ prisma/schema.prisma | 12 +++++++++ 2 files changed, 38 insertions(+) create mode 100644 prisma/migrations/0057_user_onboarding_step/migration.sql diff --git a/prisma/migrations/0057_user_onboarding_step/migration.sql b/prisma/migrations/0057_user_onboarding_step/migration.sql new file mode 100644 index 000000000..de990f6d8 --- /dev/null +++ b/prisma/migrations/0057_user_onboarding_step/migration.sql @@ -0,0 +1,26 @@ +-- v1.4.25 W14b — onboarding wizard resume-state. +-- +-- Adds `onboarding_step` to the `users` table so the rebuilt multi-step +-- wizard at `/onboarding/[step]` can resume the user at the highest +-- step they reached. Without this column, closing the tab mid-flow +-- wipes progress and forces users back to step 0. +-- +-- Step encoding (mirrors `src/components/onboarding/OnboardingShell.tsx` +-- and `src/app/onboarding/[step]/page.tsx`): +-- 0 = welcome (carousel / value-prop intro) +-- 1 = goals ("what do you want to track?") +-- 2 = source ("connect a source" — Withings / Apple Health / manual) +-- 3 = baseline (first measurement / sync confirmation) +-- 4 = done (success screen; same write that flips +-- `onboarding_completed_at` from NULL to NOW()) +-- +-- Default 0 keeps the column non-null in practice for every new user, +-- while existing pre-W14b rows stay NULL (because the `DEFAULT 0` +-- only applies to *new* inserts on PostgreSQL — existing rows are not +-- backfilled). Wizard mount code treats NULL as 0. +-- +-- The `IF NOT EXISTS` guards make the migration idempotent — if the +-- column landed via a prior dev-DB hand-edit, the migration still +-- runs cleanly to completion. +ALTER TABLE "users" + ADD COLUMN IF NOT EXISTS "onboarding_step" INTEGER DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ae89b7a93..d729e5b78 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -87,6 +87,18 @@ model User { // Onboarding onboardingCompletedAt DateTime? @map("onboarding_completed_at") + // v1.4.25 W14b — last persisted onboarding wizard step. + // Encodes resume-from-where-you-left-off semantics for the rebuilt + // multi-step wizard at `/onboarding/[step]`. Values mirror the + // wizard's step indices: + // 0 = welcome + // 1 = goals + // 2 = source + // 3 = baseline + // 4 = done (triggers `onboardingCompletedAt` flip on the same + // round-trip — the column stays at 4 for completed users) + // Null = legacy pre-W14b user; the wizard treats null as 0 on mount. + onboardingStep Int? @default(0) @map("onboarding_step") // v1.4.15 Phase B5: tracks whether the user has finished (or // explicitly dismissed) the spotlight tour that overlays the // dashboard on first arrival. Distinct from the wizard at