create table if not exists site_home_featured_experts (
  expert_id uuid primary key references expert_profiles(id) on delete cascade,
  sort_order integer not null default 10,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

insert into site_home_featured_experts (expert_id, sort_order)
select id, row_number() over (order by updated_at desc, created_at desc, id) * 10
from expert_profiles
where status = 'published'
  and deleted_at is null
order by updated_at desc, created_at desc, id
limit 4
on conflict (expert_id) do nothing;
