alter table public.video_explanations
  add column if not exists source_hash text,
  add column if not exists metadata jsonb not null default '{}'::jsonb;

alter table public.question_videos
  add column if not exists metadata jsonb not null default '{}'::jsonb;

alter table public.scoreline_fields
  add column if not exists source_hash text,
  add column if not exists metadata jsonb not null default '{}'::jsonb;

alter table public.scoreline_schools
  add column if not exists source_hash text,
  add column if not exists metadata jsonb not null default '{}'::jsonb;

alter table public.scoreline_majors
  add column if not exists source_hash text,
  add column if not exists metadata jsonb not null default '{}'::jsonb;

alter table public.scoreline_records
  add column if not exists source_hash text,
  add column if not exists metadata jsonb not null default '{}'::jsonb;

create index if not exists idx_video_explanations_source_hash
  on public.video_explanations(tenant_id, source_hash)
  where source_hash is not null;

create index if not exists idx_scoreline_fields_source_hash
  on public.scoreline_fields(tenant_id, source_hash)
  where source_hash is not null;

create index if not exists idx_scoreline_schools_source_hash
  on public.scoreline_schools(tenant_id, source_hash)
  where source_hash is not null;

create index if not exists idx_scoreline_majors_source_hash
  on public.scoreline_majors(tenant_id, source_hash)
  where source_hash is not null;

create index if not exists idx_scoreline_records_source_hash
  on public.scoreline_records(tenant_id, source_hash)
  where source_hash is not null;
