LifeMate — Personal, Family & Learning Companion

infra/lifeguide-github-pages-qa
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 65 lines 3.19 KB
Raw
1 begin;
2
3 -- Explicit content-operation capabilities are independent of family/profile/JWT roles.
4 -- No default grants and no application HTTP grant endpoint.
5 create table content_capability_grant (
6 user_id uuid not null references app_user(id) on delete cascade,
7 permission text not null check(permission in ('feedback.read','feedback.review','brief.prepare')),
8 granted_at timestamptz not null default now(),
9 expires_at timestamptz not null,
10 revoked_at timestamptz,
11 primary key(user_id,permission),
12 check(expires_at>granted_at)
13 );
14
15 -- Operator-only privilege history contains no copied feedback or contact details.
16 create table content_capability_audit (
17 id uuid primary key default gen_random_uuid(),
18 target_user_id uuid not null references app_user(id) on delete cascade,
19 permission text not null check(permission in ('feedback.read','feedback.review','brief.prepare')),
20 action text not null check(action in ('grant','revoke')),
21 occurred_at timestamptz not null default now(),
22 expires_at timestamptz
23 );
24
25 create table content_review_brief (
26 id uuid primary key default gen_random_uuid(),
27 actor_user_id uuid not null references app_user(id) on delete cascade,
28 source_count integer not null check(source_count between 1 and 20),
29 created_at timestamptz not null default now()
30 );
31 create table content_review_brief_source (
32 brief_id uuid not null references content_review_brief(id) on delete cascade,
33 feedback_id uuid not null references learning_content_feedback(id) on delete cascade,
34 feedback_version integer not null check(feedback_version>0),
35 primary key(brief_id,feedback_id)
36 );
37
38 -- Store only references/hashes: retries always reconstruct CURRENT consenting state.
39 create table content_review_mutation (
40 actor_user_id uuid not null references app_user(id) on delete cascade,
41 mutation_id uuid not null,
42 operation text not null check(operation in ('review','brief')),
43 request_hash text not null check(request_hash~'^[0-9a-f]{64}$'),
44 feedback_id uuid references learning_content_feedback(id) on delete cascade,
45 brief_id uuid references content_review_brief(id) on delete cascade,
46 accepted_at timestamptz not null default now(),
47 primary key(actor_user_id,mutation_id),
48 check((operation='review' and feedback_id is not null and brief_id is null)
49 or (operation='brief' and feedback_id is null and brief_id is not null))
50 );
51 create table content_review_audit (
52 id uuid primary key default gen_random_uuid(),
53 actor_user_id uuid not null references app_user(id) on delete cascade,
54 feedback_id uuid not null references learning_content_feedback(id) on delete cascade,
55 before_status text not null check(before_status in ('received','triaged','planned','declined')),
56 after_status text not null check(after_status in ('triaged','planned','declined')),
57 before_version integer not null check(before_version>0),
58 after_version integer not null check(after_version=before_version+1),
59 occurred_at timestamptz not null default now()
60 );
61 create index content_review_visible_idx on learning_content_feedback(status,created_at desc,id desc)
62 where withdrawn_at is null and share_with_content_team=true;
63 create index content_review_brief_feedback_idx on content_review_brief_source(feedback_id);
64
65 commit;