LifeMate — Personal, Family & Learning Companion
test/android-reminder-acceptance
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 | alter table education_profile add column track_code text; |
| 3 | update education_profile set track_code='common' where national_grade<10; |
| 4 | alter table education_profile add constraint education_profile_track_check check ((national_grade<10 and track_code='common') or (national_grade>=10 and (track_code is null or track_code in ('math','experimental','humanities')))); |
| 5 | alter table curriculum_subject add column subject_code text; |
| 6 | alter table textbook_catalog add column stable_book_key text unique, add column book_code text, add column track_codes text[] not null default '{common}', add column variant text not null default 'standard' check(variant in('standard','experimental','religious_variant','gifted')), add column edition_verification text not null default 'unverified' check(edition_verification in('verified','unverified')), add column sequence_verification text not null default 'unverified' check(sequence_verification in('official_toc','provider_index','unverified')), add column source_evidence_url text, add column alignment_notes_fa text not null default 'چاپ و انطباق منابع تأیید نشده است.'; |
| 7 | create table learning_unit ( |
| 8 | id uuid primary key default gen_random_uuid(),textbook_id uuid not null references textbook_catalog(id),unit_key text not null check(unit_key~'^[a-z0-9][a-z0-9-]{0,79}$'),title_fa text not null,order_index integer not null check(order_index>0),index_kind text not null check(index_kind in('page','lesson','chapter')),source_evidence_url text not null,active boolean not null default true,unique(textbook_id,unit_key) |
| 9 | ); |
| 10 | create index learning_unit_order_idx on learning_unit(textbook_id,order_index,unit_key); |
| 11 | create table learning_video_resource ( |
| 12 | id uuid primary key default gen_random_uuid(),unit_id uuid not null references learning_unit(id),aparat_id text not null check(aparat_id~'^[A-Za-z0-9]{5,64}$'),canonical_aparat_id text check(canonical_aparat_id is null or canonical_aparat_id~'^[A-Za-z0-9]{5,64}$'),title_fa text not null,creator_name text not null,creator_url text not null check(creator_url~'^https://www\.aparat\.com/[A-Za-z0-9_.-]+$'),source_evidence_url text not null,verification_status text not null check(verification_status in('index_verified','metadata_verified','embed_verified')),pedagogical_review text not null default 'unverified' check(pedagogical_review in('unverified','full_reviewed')),duration_seconds integer check(duration_seconds is null or duration_seconds>0),free_access boolean,checked_at timestamptz not null,quality_notes_fa text not null,publication_status text not null default 'draft' check(publication_status in('draft','published','withdrawn')),review_record jsonb,material_hash text not null check(material_hash~'^[a-f0-9]{64}$'),unique(unit_id,aparat_id), |
| 13 | constraint full_review_before_publication check(publication_status<>'published' or ( |
| 14 | free_access is true and pedagogical_review='full_reviewed' and verification_status in('metadata_verified','embed_verified') and jsonb_typeof(review_record)='object' |
| 15 | and length(trim(coalesce(review_record->>'reviewerName','')))>0 and length(trim(coalesce(review_record->>'reviewedAt','')))>0 |
| 16 | and coalesce(review_record->>'watchedEntireVideo'='true',false) and coalesce(review_record->>'editionAligned'='true',false) |
| 17 | and coalesce(review_record->>'accuracyApproved'='true',false) and coalesce(review_record->>'suitabilityApproved'='true',false) |
| 18 | and coalesce(review_record->>'embedRightsApproved'='true',false) and coalesce(review_record->>'questionCoverageReviewed'='true',false) |
| 19 | and length(trim(coalesce(review_record->>'alignmentNotes','')))>0 and length(trim(coalesce(review_record->>'accuracyNotes','')))>0 |
| 20 | and length(trim(coalesce(review_record->>'suitabilityNotes','')))>0 and length(trim(coalesce(review_record->>'embedRightsEvidence','')))>0 |
| 21 | and length(trim(coalesce(review_record->>'questionCoverageNotes','')))>0 |
| 22 | )) |
| 23 | ); |
| 24 | create index learning_video_unit_publication_idx on learning_video_resource(unit_id,publication_status); |
| 25 | create function validate_learning_publication() returns trigger language plpgsql as $$ |
| 26 | declare book record; reviewed timestamptz; |
| 27 | begin |
| 28 | if new.publication_status='published' then |
| 29 | select t.book_code,t.edition_verification,t.source_evidence_url book_evidence_url,s.school_year,u.unit_key,u.source_evidence_url unit_evidence_url,u.active into book from learning_unit u join textbook_catalog t on t.id=u.textbook_id join curriculum_subject s on s.id=t.curriculum_subject_id where u.id=new.unit_id; |
| 30 | if not book.active or new.review_record->>'materialHash' is distinct from new.material_hash or new.review_record->>'bookEvidenceUrl' is distinct from book.book_evidence_url or new.review_record->>'unitEvidenceUrl' is distinct from book.unit_evidence_url or book.edition_verification<>'verified' or book.school_year='unknown' or new.review_record->>'bookCode' is distinct from book.book_code or new.review_record->>'schoolYear' is distinct from book.school_year or new.review_record->>'unitKey' is distinct from book.unit_key then raise exception 'full review must match verified book edition and unit' using errcode='23514'; end if; |
| 31 | begin reviewed:=(new.review_record->>'reviewedAt')::timestamptz; exception when others then raise exception 'invalid review timestamp' using errcode='23514'; end; |
| 32 | if reviewed is null or reviewed>now() then raise exception 'invalid review timestamp' using errcode='23514'; end if; |
| 33 | end if; |
| 34 | return new; |
| 35 | end $$; |
| 36 | create trigger learning_publication_guard before insert or update on learning_video_resource for each row execute function validate_learning_publication(); |
| 37 | create table learning_progress ( |
| 38 | owner_user_id uuid not null references app_user(id) on delete cascade,unit_id uuid not null references learning_unit(id),status text not null check(status in('not_started','in_progress','completed')),source text not null check(source='self_reported'),version bigint not null check(version>0),updated_at timestamptz not null default now(),primary key(owner_user_id,unit_id) |
| 39 | ); |
| 40 | create table learning_progress_mutation ( |
| 41 | owner_user_id uuid not null references app_user(id) on delete cascade,mutation_id uuid not null,unit_id uuid not null references learning_unit(id),request_hash text not null check(length(request_hash)=64),acknowledgement jsonb not null,accepted_at timestamptz not null default now(),primary key(owner_user_id,mutation_id) |
| 42 | ); |
| 43 | alter table plan_item add column learning_unit_id uuid references learning_unit(id); |
| 44 | commit; |