LifeMate — Personal, Family & Learning Companion

docs/offline-data-rescue-options
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 54 lines 2.51 KB
Raw
1 begin;
2
3 alter table family_membership add column version integer not null default 1 check(version>0),
4 add column updated_at timestamptz not null default now();
5 update family_membership set updated_at=joined_at;
6 create function membership_lifecycle_revision() returns trigger language plpgsql as $$
7 begin
8 if new.role is distinct from old.role or new.is_admin is distinct from old.is_admin
9 or new.ended_at is distinct from old.ended_at or new.joined_at is distinct from old.joined_at then
10 new.version:=old.version+1;
11 new.updated_at:=statement_timestamp();
12 else
13 new.version:=old.version;
14 new.updated_at:=old.updated_at;
15 end if;
16 return new;
17 end $$;
18 create trigger family_membership_lifecycle_revision before update on family_membership
19 for each row execute function membership_lifecycle_revision();
20
21 alter table family_invitation add column version integer not null default 1 check(version>0),
22 add column updated_at timestamptz not null default now();
23 update family_invitation set updated_at=created_at;
24 create function invitation_lifecycle_revision() returns trigger language plpgsql as $$
25 begin
26 if new.status is distinct from old.status or new.expires_at is distinct from old.expires_at
27 or new.intended_role is distinct from old.intended_role or new.intended_theme is distinct from old.intended_theme
28 or new.invited_email_normalized is distinct from old.invited_email_normalized
29 or new.invited_phone_normalized is distinct from old.invited_phone_normalized
30 or new.invited_by is distinct from old.invited_by or new.token_digest is distinct from old.token_digest
31 or new.accepted_by is distinct from old.accepted_by or new.accepted_at is distinct from old.accepted_at then
32 new.version:=old.version+1;
33 new.updated_at:=statement_timestamp();
34 else
35 new.version:=old.version;
36 new.updated_at:=old.updated_at;
37 end if;
38 return new;
39 end $$;
40 create trigger family_invitation_lifecycle_revision before update on family_invitation
41 for each row execute function invitation_lifecycle_revision();
42
43 create table family_lifecycle_mutation (
44 actor_user_id uuid not null references app_user(id) on delete cascade,
45 mutation_id uuid not null,
46 family_id uuid not null references family_workspace(id) on delete cascade,
47 operation text not null check(operation in ('role','admin_transfer','invitation_revoke')),
48 request_hash text not null check(request_hash~'^[0-9a-f]{64}$'),
49 target_id uuid not null,
50 accepted_at timestamptz not null default now(),
51 primary key(actor_user_id,mutation_id)
52 );
53
54 commit;