Validate on Linux Node 22 and PostgreSQL 17: 3894 frontend tests and 64 database tests pass, with no removed test names or new failures. Preserve static Home, bounded gzip, assertion-change records and manual acceptance gaps. Co-Authored-By: Claude Code <noreply@anthropic.com>
43 lines
1.5 KiB
PL/PgSQL
43 lines
1.5 KiB
PL/PgSQL
-- Legacy JSON is not evidence of an accepted/confirmed rectification.
|
|
-- This is a corrective migration, not a rewrite of the deployed backfill.
|
|
begin;
|
|
lock table public.chart_profiles in access exclusive mode;
|
|
alter table public.chart_profiles disable trigger chart_profiles_guard_birth;
|
|
update public.chart_profiles
|
|
set birth_time_status = 'reported',
|
|
active_birth_time = null,
|
|
active_birth_date = null,
|
|
active_birth_timezone_offset = null
|
|
where role = 'other'
|
|
and (birth_time_status in ('accepted', 'confirmed')
|
|
or active_birth_time is not null
|
|
or active_birth_date is not null
|
|
or active_birth_timezone_offset is not null);
|
|
alter table public.chart_profiles enable trigger chart_profiles_guard_birth;
|
|
|
|
create or replace function public.chart_profiles_guard_limit()
|
|
returns trigger
|
|
language plpgsql
|
|
set search_path = ''
|
|
as $$
|
|
declare
|
|
others integer;
|
|
begin
|
|
if new.role is distinct from 'other' then
|
|
raise exception 'chart_subject_self_mirror_retired';
|
|
end if;
|
|
if tg_op = 'INSERT' or new.user_id is distinct from old.user_id then
|
|
-- The lock and count are separate statements: after a competing insert
|
|
-- commits, READ COMMITTED sees its row before deciding the limit.
|
|
perform pg_catalog.pg_advisory_xact_lock(pg_catalog.hashtextextended(new.user_id::text, 73031));
|
|
select count(*) into others from public.chart_profiles
|
|
where user_id = new.user_id and role = 'other';
|
|
if others >= 4 then
|
|
raise exception 'subject_limit_reached';
|
|
end if;
|
|
end if;
|
|
return new;
|
|
end;
|
|
$$;
|
|
commit;
|