-- ================================================
-- Migration: Update SAC code from 999293 to 999294
-- Date: 2026-08-19
-- Applies to every program_type_v1 / program_v1 / program_session row currently
-- set to the old SAC (999293), across all program types (PT_TAT, PT_PAP, etc.),
-- not just PT_ENTRAINMENT (see database/entrainment-migrations-v2(2026-08-10)/
-- 01program-type-refresh.sql, which sources PT_ENTRAINMENT's own SAC from 999294
-- directly and is unaffected by this migration).
-- Scoped to live rows only (deleted_at IS NULL).
--
-- Also includes: R1016 card-view tagline fix, scoped to program_type_v1 only
-- (PT_ENTRAINMENT's description). Duplicates the same change already made in
-- 01program-type-refresh.sql's draft — included here too so it applies even if
-- that draft migration is never run on its own.
-- ================================================

--- program_type_v1: rows before update
select id, name, key, services_accounting_code from program_type_v1
where services_accounting_code = '999293' and deleted_at is null;

update program_type_v1
set services_accounting_code = '999294'
where services_accounting_code = '999293' and deleted_at is null;

--- program_type_v1: PT_ENTRAINMENT description before update (R1016)
select id, name, key, description from program_type_v1
where key = 'PT_ENTRAINMENT' and deleted_at is null;

update program_type_v1
set description = 'A residential experience with Mahatria'
where key = 'PT_ENTRAINMENT' and deleted_at is null;


-- email_sender_name
select id, name, key, email_sender_name from program_type_v1
where key = 'PT_ENTRAINMENT' and deleted_at is null;

update program_type_v1
set email_sender_name = 'Entrainment 26'
where key = 'PT_ENTRAINMENT' and deleted_at is null;

-- max_proxy_registrations: program_type_v1
select id, name, key, max_proxy_registrations from program_type_v1
where key = 'PT_ENTRAINMENT' and deleted_at is null;

update program_type_v1
set max_proxy_registrations = 4
where key = 'PT_ENTRAINMENT' and deleted_at is null;

-- max_proxy_registrations: program_v1 (existing Entrainment programs)
select id, name, program_type_id, max_proxy_registrations from program_v1
where program_type_id = (select id from program_type_v1 where key = 'PT_ENTRAINMENT')
  and deleted_at is null;

update program_v1
set max_proxy_registrations = 4
where program_type_id = (select id from program_type_v1 where key = 'PT_ENTRAINMENT')
  and deleted_at is null;

-- is_proforma_allowed: program_type_v1
select id, name, key, is_proforma_allowed from program_type_v1
where key = 'PT_ENTRAINMENT' and deleted_at is null;

update program_type_v1
set is_proforma_allowed = false
where key = 'PT_ENTRAINMENT' and deleted_at is null;

-- is_proforma_allowed: program_v1 (existing Entrainment programs)
select id, name, program_type_id, is_proforma_allowed from program_v1
where program_type_id = (select id from program_type_v1 where key = 'PT_ENTRAINMENT')
  and deleted_at is null;

update program_v1
set is_proforma_allowed = false
where program_type_id = (select id from program_type_v1 where key = 'PT_ENTRAINMENT')
  and deleted_at is null;
