LifeMate — Personal, Family & Learning Companion
feat/child-device-safety
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
| 1 | begin; |
| 2 | |
| 3 | -- Reuse the existing planner; its legacy status remains compatible. |
| 4 | alter table plan_item add column activity_version bigint not null default 0; |
| 5 | alter table plan_item add column if not exists version bigint not null default 0; |
| 6 | alter table plan_item add constraint plan_item_id_owner_unique unique(id,owner_user_id); |
| 7 | |
| 8 | create function plan_item_revision() returns trigger language plpgsql as $$ |
| 9 | begin |
| 10 | new.version := old.version+1; |
| 11 | return new; |
| 12 | end $$; |
| 13 | create trigger plan_item_revision before update on plan_item |
| 14 | for each row execute function plan_item_revision(); |
| 15 | |
| 16 | create table study_session ( |
| 17 | id uuid primary key, |
| 18 | child_user_id uuid not null references app_user(id) on delete cascade, |
| 19 | plan_item_id uuid not null, |
| 20 | source text not null check(source in ('timer','self_reported')), |
| 21 | status text not null check(status in ('running','paused','completed','archived')), |
| 22 | started_at timestamptz not null, |
| 23 | ended_at timestamptz, |
| 24 | last_event_at timestamptz not null, |
| 25 | recorded_duration_seconds integer not null default 0 check(recorded_duration_seconds>=0), |
| 26 | version integer not null default 1 check(version>0), |
| 27 | last_sync_at timestamptz not null default now(), |
| 28 | created_at timestamptz not null default now(), |
| 29 | updated_at timestamptz not null default now(), |
| 30 | archived_at timestamptz, |
| 31 | foreign key(plan_item_id,child_user_id) references plan_item(id,owner_user_id) on delete cascade, |
| 32 | check(ended_at is null or ended_at>=started_at), |
| 33 | check(last_event_at>=started_at) |
| 34 | ); |
| 35 | create index study_session_owner_idx on study_session(child_user_id,started_at desc); |
| 36 | create index study_session_plan_idx on study_session(plan_item_id) where archived_at is null; |
| 37 | |
| 38 | create table study_interval ( |
| 39 | id bigint generated always as identity primary key, |
| 40 | session_id uuid not null references study_session(id) on delete cascade, |
| 41 | starts_at timestamptz not null, |
| 42 | ends_at timestamptz, |
| 43 | check(ends_at is null or ends_at>=starts_at) |
| 44 | ); |
| 45 | create index study_interval_session_idx on study_interval(session_id,starts_at); |
| 46 | create unique index study_interval_one_running_idx on study_interval(session_id) where ends_at is null; |
| 47 | |
| 48 | create table activity_state_event ( |
| 49 | id bigint generated always as identity primary key, |
| 50 | plan_item_id uuid not null references plan_item(id) on delete cascade, |
| 51 | actor_user_id uuid not null references app_user(id), |
| 52 | state text not null check(state in ('planned','started','paused','completed','verified')), |
| 53 | source text not null check(source in ('client_timer','self_reported','guardian_confirmation')), |
| 54 | occurred_at timestamptz not null, |
| 55 | accepted_at timestamptz not null default now(), |
| 56 | version bigint not null check(version>0), |
| 57 | confirmation text, |
| 58 | unique(plan_item_id,version), |
| 59 | check((state='verified' and source='guardian_confirmation' and char_length(confirmation) between 1 and 1000) |
| 60 | or (state<>'verified' and source<>'guardian_confirmation' and confirmation is null)) |
| 61 | ); |
| 62 | create index activity_state_latest_idx on activity_state_event(plan_item_id,version desc); |
| 63 | |
| 64 | -- A separate ledger avoids changing existing planner/offline sync protocol. |
| 65 | create table study_mutation ( |
| 66 | user_id uuid not null references app_user(id) on delete cascade, |
| 67 | id uuid not null, |
| 68 | request_hash text not null, |
| 69 | response_body jsonb not null, |
| 70 | response_status integer not null, |
| 71 | accepted_at timestamptz not null default now(), |
| 72 | primary key(user_id,id) |
| 73 | ); |
| 74 | |
| 75 | commit; |