LifeMate — Personal, Family & Learning Companion
fix: extend existing notification preferences
davoodmehraban89 committed
Oct 5, 2026 at 19:42 UTC
afcf30d302f533d3cfac5130a084475bf2fa9ed3
1 file changed
+10
-116
backend/migrations/0005_iran_family_learning.sql
renamed
+10
-116
@@ -1,120 +1,13 @@
1
begin;
2
-
3
-alter table profile
4
- add column if not exists household_persona text check (household_persona in ('mother','father','child','adult')),
5
- add column if not exists sex text check (sex in ('female','male','unspecified'));
6
-
7
-create table education_profile (
8
- user_id uuid primary key references app_user(id) on delete cascade,
9
- country_code char(2) not null default 'IR' check (country_code='IR'),
10
- stage text not null check (stage in ('primary_1','primary_2','secondary_1','secondary_2')),
11
- national_grade smallint not null check (national_grade between 1 and 12),
12
- local_year smallint not null check (local_year between 1 and 3),
13
- school_name text,
14
- school_year text not null,
15
- updated_at timestamptz not null default now(),
16
- check (
17
- (stage='primary_1' and national_grade between 1 and 3 and local_year=national_grade) or
18
- (stage='primary_2' and national_grade between 4 and 6 and local_year=national_grade-3) or
19
- (stage='secondary_1' and national_grade between 7 and 9 and local_year=national_grade-6) or
20
- (stage='secondary_2' and national_grade between 10 and 12 and local_year=national_grade-9)
21
- )
22
-);
23
-
24
-create table curriculum_subject (
25
- id uuid primary key default gen_random_uuid(),
26
- country_code char(2) not null default 'IR',
27
- school_year text not null,
28
- national_grade smallint not null check (national_grade between 1 and 12),
29
- code text not null,
30
- name_fa text not null,
31
- sort_order smallint not null default 0,
32
- unique(country_code,school_year,national_grade,code)
33
-);
34
-
35
-create table textbook_catalog (
36
- id uuid primary key default gen_random_uuid(),
37
- curriculum_subject_id uuid not null references curriculum_subject(id) on delete cascade,
38
- title_fa text not null,
39
- publisher text not null default 'سازمان پژوهش و برنامهریزی آموزشی',
40
- source_host text not null default 'chap.sch.ir' check (source_host in ('chap.sch.ir','medu.gov.ir')),
41
- source_url text not null check (source_url ~ '^https://'),
42
- redistribution_status text not null default 'link_only' check (redistribution_status in ('link_only','licensed_bundle')),
43
- unique(curriculum_subject_id,title_fa)
44
-);
45
-
46
-create table iran_calendar_event (
47
- id uuid primary key default gen_random_uuid(),
48
- jalali_year smallint not null check (jalali_year between 1300 and 1600),
49
- jalali_month smallint not null check (jalali_month between 1 and 12),
50
- jalali_day smallint not null check (jalali_day between 1 and 31),
51
- title_fa text not null,
52
- is_official_holiday boolean not null default false,
53
- source_name text not null,
54
- source_url text not null check (source_url ~ '^https://'),
55
- unique(jalali_year,jalali_month,jalali_day,title_fa)
56
-);
57
-
58
-create table notification_preference (
59
- user_id uuid primary key references app_user(id) on delete cascade,
60
- in_app_banner boolean not null default true,
61
- push_enabled boolean not null default false,
62
- planner_reminders boolean not null default true,
63
- school_reminders boolean not null default true,
64
- calendar_reminders boolean not null default true,
65
- cycle_reminders boolean not null default false,
66
- sensitive_preview boolean not null default false,
67
- updated_at timestamptz not null default now()
68
-);
69
-
70
-create table menstrual_cycle_entry (
71
- id uuid primary key default gen_random_uuid(),
72
- owner_user_id uuid not null references app_user(id) on delete cascade,
73
- starts_on date not null,
74
- ends_on date,
75
- predicted_next_on date,
76
- symptoms text[] not null default '{}',
77
- notes text,
78
- reminder_enabled boolean not null default false,
79
- created_at timestamptz not null default now(),
80
- updated_at timestamptz not null default now(),
81
- check (ends_on is null or ends_on >= starts_on),
82
- check (predicted_next_on is null or predicted_next_on > starts_on)
83
-);
2
+alter table profile add column if not exists household_persona text check (household_persona in ('mother','father','child','adult')), add column if not exists sex text check (sex in ('female','male','unspecified'));
3
+create table education_profile (user_id uuid primary key references app_user(id) on delete cascade,country_code char(2) not null default 'IR' check(country_code='IR'),stage text not null check(stage in('primary_1','primary_2','secondary_1','secondary_2')),national_grade smallint not null check(national_grade between 1 and 12),local_year smallint not null check(local_year between 1 and 3),school_name text,school_year text not null,updated_at timestamptz not null default now(),check((stage='primary_1' and national_grade between 1 and 3 and local_year=national_grade)or(stage='primary_2' and national_grade between 4 and 6 and local_year=national_grade-3)or(stage='secondary_1' and national_grade between 7 and 9 and local_year=national_grade-6)or(stage='secondary_2' and national_grade between 10 and 12 and local_year=national_grade-9)));
4
+create table curriculum_subject (id uuid primary key default gen_random_uuid(),country_code char(2) not null default 'IR',school_year text not null,national_grade smallint not null check(national_grade between 1 and 12),code text not null,name_fa text not null,sort_order smallint not null default 0,unique(country_code,school_year,national_grade,code));
5
+create table textbook_catalog (id uuid primary key default gen_random_uuid(),curriculum_subject_id uuid not null references curriculum_subject(id) on delete cascade,title_fa text not null,publisher text not null default 'سازمان پژوهش و برنامهریزی آموزشی',source_host text not null default 'chap.sch.ir' check(source_host in('chap.sch.ir','medu.gov.ir')),source_url text not null check(source_url~'^https://'),redistribution_status text not null default 'link_only' check(redistribution_status in('link_only','licensed_bundle')),unique(curriculum_subject_id,title_fa));
6
+create table iran_calendar_event (id uuid primary key default gen_random_uuid(),jalali_year smallint not null check(jalali_year between 1300 and 1600),jalali_month smallint not null check(jalali_month between 1 and 12),jalali_day smallint not null check(jalali_day between 1 and 31),title_fa text not null,is_official_holiday boolean not null default false,source_name text not null,source_url text not null check(source_url~'^https://'),unique(jalali_year,jalali_month,jalali_day,title_fa));
7
+alter table notification_preference add column if not exists in_app_banner boolean not null default true,add column if not exists push_enabled boolean not null default false,add column if not exists planner_reminders boolean not null default true,add column if not exists school_reminders boolean not null default true,add column if not exists calendar_reminders boolean not null default true,add column if not exists cycle_reminders boolean not null default false,add column if not exists sensitive_preview boolean not null default false;
8
+create table menstrual_cycle_entry (id uuid primary key default gen_random_uuid(),owner_user_id uuid not null references app_user(id) on delete cascade,starts_on date not null,ends_on date,predicted_next_on date,symptoms text[] not null default '{}',notes text,reminder_enabled boolean not null default false,created_at timestamptz not null default now(),updated_at timestamptz not null default now(),check(ends_on is null or ends_on>=starts_on),check(predicted_next_on is null or predicted_next_on>starts_on));
9
create index menstrual_cycle_owner_date_idx on menstrual_cycle_entry(owner_user_id,starts_on desc);
85
-
86
-insert into curriculum_subject(school_year,national_grade,code,name_fa,sort_order) values
87
-('1405-1406',7,'fa','فارسی',10),
88
-('1405-1406',7,'writing','نگارش',20),
89
-('1405-1406',7,'math','ریاضی',30),
90
-('1405-1406',7,'science','علوم تجربی',40),
91
-('1405-1406',7,'social','مطالعات اجتماعی',50),
92
-('1405-1406',7,'arabic','عربی',60),
93
-('1405-1406',7,'quran','قرآن',70),
94
-('1405-1406',7,'religion','پیامهای آسمان',80),
95
-('1405-1406',7,'english','انگلیسی',90),
96
-('1405-1406',7,'worktech','کار و فناوری',100),
97
-('1405-1406',7,'thinking','تفکر و سبک زندگی',110),
98
-('1405-1406',7,'pe','تربیت بدنی و سلامت',120)
99
-on conflict do nothing;
100
-
101
-insert into textbook_catalog(curriculum_subject_id,title_fa,source_url)
102
-select id,name_fa,'https://chap.sch.ir/' from curriculum_subject
103
-where school_year='1405-1406' and national_grade=7
104
-on conflict do nothing;
105
-
106
-insert into iran_calendar_event(jalali_year,jalali_month,jalali_day,title_fa,is_official_holiday,source_name,source_url) values
107
-(1405,1,1,'آغاز نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
108
-(1405,1,2,'عید نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
109
-(1405,1,3,'عید نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
110
-(1405,1,4,'عید نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
111
-(1405,1,12,'روز جمهوری اسلامی ایران',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
112
-(1405,1,13,'روز طبیعت',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
113
-(1405,3,14,'رحلت امام خمینی',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
114
-(1405,3,15,'قیام ۱۵ خرداد',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
115
-(1405,11,22,'پیروزی انقلاب اسلامی ایران',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),
116
-(1405,12,29,'روز ملی شدن صنعت نفت ایران',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/')
117
-on conflict do nothing;
118
-
10
+insert into curriculum_subject(school_year,national_grade,code,name_fa,sort_order) values ('1405-1406',7,'fa','فارسی',10),('1405-1406',7,'writing','نگارش',20),('1405-1406',7,'math','ریاضی',30),('1405-1406',7,'science','علوم تجربی',40),('1405-1406',7,'social','مطالعات اجتماعی',50),('1405-1406',7,'arabic','عربی',60),('1405-1406',7,'quran','قرآن',70),('1405-1406',7,'religion','پیامهای آسمان',80),('1405-1406',7,'english','انگلیسی',90),('1405-1406',7,'worktech','کار و فناوری',100),('1405-1406',7,'thinking','تفکر و سبک زندگی',110),('1405-1406',7,'pe','تربیت بدنی و سلامت',120) on conflict do nothing;
11
+insert into textbook_catalog(curriculum_subject_id,title_fa,source_url) select id,name_fa,'https://chap.sch.ir/' from curriculum_subject where school_year='1405-1406' and national_grade=7 on conflict do nothing;
12
+insert into iran_calendar_event(jalali_year,jalali_month,jalali_day,title_fa,is_official_holiday,source_name,source_url) values (1405,1,1,'آغاز نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,1,2,'عید نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,1,3,'عید نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,1,4,'عید نوروز',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,1,12,'روز جمهوری اسلامی ایران',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,1,13,'روز طبیعت',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,3,14,'رحلت امام خمینی',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,3,15,'قیام ۱۵ خرداد',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,11,22,'پیروزی انقلاب اسلامی ایران',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/'),(1405,12,29,'روز ملی شدن صنعت نفت ایران',true,'تقویم رسمی کشور ۱۴۰۵ — مرکز تقویم مؤسسه ژئوفیزیک دانشگاه تهران','https://calendar.ut.ac.ir/') on conflict do nothing;
13
commit;
\ No newline at end of file