LifeMate — Personal, Family & Learning Companion

fix/personal-notification-controls
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
sql 44 lines 2.15 KB
Raw
1 begin;
2
3 alter table app_user alter column email_normalized drop not null;
4 alter table app_user add column phone_normalized text unique;
5 alter table app_user add column phone_verified_at timestamptz;
6 alter table app_user add constraint app_user_phone_format
7 check (phone_normalized is null or phone_normalized ~ '^\+[1-9][0-9]{7,14}$');
8 alter table app_user add constraint app_user_contact_required
9 check (email_normalized is not null or phone_normalized is not null);
10
11 alter table family_invitation alter column invited_email_normalized drop not null;
12 alter table family_invitation add column invited_phone_normalized text;
13 alter table family_invitation add constraint family_invitation_contact_required
14 check (num_nonnulls(invited_email_normalized,invited_phone_normalized)=1);
15 alter table family_invitation add constraint family_invitation_phone_format
16 check (invited_phone_normalized is null or invited_phone_normalized ~ '^\+[1-9][0-9]{7,14}$');
17
18 create table auth_delivery_attempt (
19 id uuid primary key default gen_random_uuid(),
20 recipient_digest text not null check (recipient_digest ~ '^[a-f0-9]{64}$'),
21 purpose text not null check (purpose in ('email_verification','password_reset','phone_otp')),
22 user_id uuid references app_user(id) on delete set null,
23 status text not null default 'pending'
24 check (status in ('pending','accepted','failed','unconfigured','not_needed')),
25 requested_at timestamptz not null default now(),
26 updated_at timestamptz not null default now()
27 );
28 create index auth_delivery_recipient_window_idx
29 on auth_delivery_attempt(recipient_digest,purpose,requested_at desc);
30
31 create table auth_phone_challenge (
32 id uuid primary key,
33 user_id uuid references app_user(id) on delete cascade,
34 purpose text not null check (purpose in ('verify','login','recovery')),
35 code_digest text not null check (code_digest ~ '^[a-f0-9]{64}$'),
36 attempts smallint not null default 0 check (attempts between 0 and 5),
37 expires_at timestamptz not null,
38 used_at timestamptz,
39 created_at timestamptz not null default now(),
40 check (expires_at > created_at)
41 );
42 create index auth_phone_challenge_owner_idx on auth_phone_challenge(user_id,created_at desc);
43
44 commit;