1- create table if not exists user_stats_aggregate (
1+ create table if not exists user_stats_aggregate_daily (
22 user_id int not null ,
3- window_type text not null check (window_type in (
4- ' daily' , ' weekly' , ' monthly' , ' yearly'
5- )),
63 window_start timestamptz not null ,
74 window_end timestamptz not null ,
85 lang_durations jsonb default ' {}' ::jsonb,
@@ -12,33 +9,23 @@ create table if not exists user_stats_aggregate (
129 activity_durations jsonb default ' {}' ::jsonb,
1310 created_at timestamptz default now(),
1411 updated_at timestamptz default now(),
15- primary key (user_id, window_type, window_start)
12+ primary key (user_id, window_start)
1613);
1714
18- create index if not exists idx_user_stats_time_range on user_stats_aggregate(user_id, window_type, window_start desc );
19- create index if not exists idx_user_stats_updated on user_stats_aggregate(updated_at) where window_type like ' rolling%' ;
20-
21- create table if not exists user_stats_rolling (
22- user_id int not null ,
23- window_type text not null check (window_type in (
24- ' rolling_24h' , ' rolling_7d' , ' rolling_30d' , ' rolling_365d'
25- )),
15+ create table if not exists user_stats_rolling_day (
16+ user_id int primary key ,
2617 lang_durations jsonb default ' {}' ::jsonb,
2718 machine_durations jsonb default ' {}' ::jsonb,
2819 editor_durations jsonb default ' {}' ::jsonb,
2920 project_durations jsonb default ' {}' ::jsonb,
3021 activity_durations jsonb default ' {}' ::jsonb,
3122 created_at timestamptz default now(),
32- updated_at timestamptz default now(),
33- primary key (user_id, window_type)
23+ updated_at timestamptz default now()
3424);
3525
36- create table if not exists user_project_stats_aggregate (
26+ create table if not exists user_project_stats_aggregate_daily (
3727 user_id integer ,
3828 project_path varchar (500 ) not null ,
39- window_type text not null check (window_type in (
40- ' daily' , ' weekly' , ' monthly' , ' yearly'
41- )),
4229 window_start timestamp not null ,
4330 window_end timestamp not null ,
4431 lang_durations jsonb,
@@ -47,22 +34,19 @@ create table if not exists user_project_stats_aggregate (
4734 activity_durations jsonb,
4835 files_durations jsonb,
4936 updated_at timestamptz default now(),
50- unique (user_id, project_path, window_type, window_start)
37+ unique (user_id, project_path, window_start)
5138);
5239
53- create table if not exists user_project_stats_rolling (
40+ create table if not exists user_project_stats_rolling_day (
5441 user_id integer ,
5542 project_path varchar (500 ) not null ,
56- window_type text not null check (window_type in (
57- ' rolling_24h' , ' rolling_7d' , ' rolling_30d' , ' rolling_365d'
58- )),
5943 lang_durations jsonb,
6044 machine_durations jsonb,
6145 editor_durations jsonb,
6246 activity_durations jsonb,
6347 files_durations jsonb,
6448 updated_at timestamptz default now(),
65- unique (user_id, project_path, window_type )
49+ unique (user_id, project_path)
6650);
6751
6852create table if not exists user_project_session (
0 commit comments