8ed6118b9a
Users pick a clock range instead of a coarse period plus notes, so rectification and window consult scan that range instead of a leftover afternoon bucket. Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
1.9 KiB
PL/PgSQL
63 lines
1.9 KiB
PL/PgSQL
begin;
|
|
|
|
-- BUG-353: period_only declarations are a start/end clock window, not a
|
|
-- coarse bucket plus free-text clue. Rectification and window consultation
|
|
-- read these columns; birth_time_period remains a legacy fallback.
|
|
|
|
alter table public.profiles
|
|
add column if not exists declared_window_start text,
|
|
add column if not exists declared_window_end text;
|
|
|
|
alter table public.profiles
|
|
drop constraint if exists profiles_declared_window_clocks;
|
|
|
|
alter table public.profiles
|
|
add constraint profiles_declared_window_clocks check (
|
|
(declared_window_start is null and declared_window_end is null)
|
|
or (
|
|
declared_window_start ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'
|
|
and declared_window_end ~ '^([01][0-9]|2[0-3]):[0-5][0-9]$'
|
|
and declared_window_start is distinct from declared_window_end
|
|
)
|
|
);
|
|
|
|
update public.profiles
|
|
set
|
|
declared_window_start = case birth_time_period
|
|
when 'early_morning' then '04:00'
|
|
when 'morning' then '08:00'
|
|
when 'afternoon' then '12:00'
|
|
when 'evening' then '18:00'
|
|
when 'late_night' then '23:00'
|
|
else declared_window_start
|
|
end,
|
|
declared_window_end = case birth_time_period
|
|
when 'early_morning' then '07:59'
|
|
when 'morning' then '11:59'
|
|
when 'afternoon' then '17:59'
|
|
when 'evening' then '22:59'
|
|
when 'late_night' then '03:59'
|
|
else declared_window_end
|
|
end
|
|
where birth_time_source = 'period_only'
|
|
and declared_window_start is null
|
|
and declared_window_end is null
|
|
and birth_time_period in ('early_morning', 'morning', 'afternoon', 'evening', 'late_night');
|
|
|
|
grant select (
|
|
declared_window_start,
|
|
declared_window_end
|
|
) on table public.profiles to service_role;
|
|
|
|
grant insert (
|
|
declared_window_start,
|
|
declared_window_end
|
|
) on table public.profiles to service_role;
|
|
|
|
grant update (
|
|
declared_window_start,
|
|
declared_window_end
|
|
) on table public.profiles to service_role;
|
|
|
|
commit;
|