@davoodmehraban89 / LifeMate / commits / 3bdab27
Fork 0

LifeMate — Personal, Family & Learning Companion

feat: add phase 4 AI learning wellbeing schema

davoodmehraban89 committed Oct 5, 2026 at 15:54 UTC 3bdab279fd83e8ab77ea9280ec2c8cdd05c21bc7
1 file changed +42
backend/migrations/0004_ai_learning_wellbeing.sql new
+42
@@ -0,0 +1,42 @@
1 +create table if not exists learning_goal (
2 + id uuid primary key default gen_random_uuid(),
3 + owner_user_id uuid not null references app_user(id) on delete cascade,
4 + subject_id uuid references academic_subject(id) on delete set null,
5 + title text not null,
6 + target text,
7 + status text not null default 'active' check (status in ('active','completed','archived')),
8 + created_at timestamptz not null default now(), updated_at timestamptz not null default now()
9 +);
10 +create table if not exists learning_checkin (
11 + id uuid primary key default gen_random_uuid(), owner_user_id uuid not null references app_user(id) on delete cascade,
12 + learning_goal_id uuid references learning_goal(id) on delete set null,
13 + confidence smallint check(confidence between 1 and 5), difficulty smallint check(difficulty between 1 and 5), note text,
14 + created_at timestamptz not null default now()
15 +);
16 +create table if not exists wellbeing_checkin (
17 + id uuid primary key default gen_random_uuid(), owner_user_id uuid not null references app_user(id) on delete cascade,
18 + mood smallint not null check(mood between 1 and 5), energy smallint check(energy between 1 and 5), stress smallint check(stress between 1 and 5), note text,
19 + visibility text not null default 'private' check(visibility in ('private','guardian_summary')),
20 + created_at timestamptz not null default now()
21 +);
22 +create table if not exists ai_guide_session (
23 + id uuid primary key default gen_random_uuid(), owner_user_id uuid not null references app_user(id) on delete cascade,
24 + guide_kind text not null check(guide_kind in ('study','planner','wellbeing')),
25 + status text not null default 'active' check(status in ('active','closed')),
26 + created_at timestamptz not null default now(), updated_at timestamptz not null default now()
27 +);
28 +create table if not exists ai_guide_message (
29 + id uuid primary key default gen_random_uuid(), session_id uuid not null references ai_guide_session(id) on delete cascade,
30 + author text not null check(author in ('user','assistant','system')), body text not null,
31 + safety_class text not null default 'ordinary' check(safety_class in ('ordinary','supportive','urgent_review')),
32 + created_at timestamptz not null default now()
33 +);
34 +create table if not exists ai_plan_proposal (
35 + id uuid primary key default gen_random_uuid(), owner_user_id uuid not null references app_user(id) on delete cascade,
36 + session_id uuid references ai_guide_session(id) on delete set null, title text not null, proposal jsonb not null,
37 + status text not null default 'proposed' check(status in ('proposed','accepted','rejected')),
38 + created_at timestamptz not null default now(), decided_at timestamptz
39 +);
40 +create index if not exists learning_goal_owner_idx on learning_goal(owner_user_id,status);
41 +create index if not exists wellbeing_checkin_owner_idx on wellbeing_checkin(owner_user_id,created_at desc);
42 +create index if not exists ai_guide_session_owner_idx on ai_guide_session(owner_user_id,created_at desc);