added habit_streaks to habits table
This commit is contained in:
20
supabase/migrations/20260524150000_habits_streak.sql
Normal file
20
supabase/migrations/20260524150000_habits_streak.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
alter table public.habits
|
||||
add column if not exists streak int not null default 0,
|
||||
add column if not exists last_completed_on date;
|
||||
|
||||
alter table public.habits
|
||||
drop constraint if exists habits_streak_check;
|
||||
|
||||
alter table public.habits
|
||||
add constraint habits_streak_check
|
||||
check (streak >= 0);
|
||||
|
||||
update public.habits h
|
||||
set last_completed_on = latest.completed_on
|
||||
from (
|
||||
select habit_id, max(completed_on) as completed_on
|
||||
from public.habit_logs
|
||||
group by habit_id
|
||||
) as latest
|
||||
where h.id = latest.habit_id
|
||||
and h.last_completed_on is null;
|
||||
Reference in New Issue
Block a user