-- ================================================
-- PT_PAP — Organisation fields on hdb_program_registration
-- 2026-08-07
-- DRAFT ONLY — not executed against any database, not yet reviewed/approved.
-- Idempotent (ADD COLUMN IF NOT EXISTS).
-- ================================================
--
-- Companion to database/migrations/2026-08-07-02-pt-pap-program-template.sql, which creates
-- the 'organisationName' / 'organisationDescription' master_question rows for PAP's
-- FS_BASICDETAILS (STEP 4b there). Those two questions were originally given
-- answer_location = NULL (routing answers through the generic customResponses JSONB path,
-- since no matching column existed) — per explicit instruction, they now get real, dedicated
-- columns instead, matching how every other FS_BASICDETAILS field on this table works
-- (full_name, mobile_number, email_address, city, etc.).
--
-- Column choice: hdb_program_registration is the same table every other FS_BASICDETAILS
-- answer_location already points at (see database/base-script/portal-base-master-data.sql:
-- 250-258 for the existing name/gender/mobileNumber/email/dob/city/profileUrl/rmContact
-- mappings) — not a new table, so no new entity/module is needed.
--
-- Write path requires BOTH of these, confirmed via registration.service.ts
-- processQuestionAnswers -> registration.repository.ts storeQuestionResponsesGrouped /
-- buildEntityDataFromAnswers: it resolves the target column via live TypeORM
-- EntityMetadata, so a column that exists in the DB but not on the entity class is silently
-- dropped, not written.
--   1. This SQL migration (the DB column) — run this file.
--   2. src/common/entities/program-registration.entity.ts (the TypeORM entity) — already
--      updated in this change: `organisationName` -> 'organisation_name',
--      `organisationDescription` -> 'organisation_description'.
--
-- Nullability: both nullable, following the existing convention for PAP/HDB-only optional
-- fields on this table (e.g. city, preferred_room_mate, other_city_name are all nullable —
-- only the universally-required core fields full_name/mobile_number/email_address are NOT
-- NULL). organisation_description is TEXT (free-form, matches notes/comments/rm_review),
-- organisation_name is VARCHAR(255) (matches full_name/preferred_room_mate/city-style
-- single-line fields).
-- ================================================

ALTER TABLE hdb_program_registration
  ADD COLUMN IF NOT EXISTS organisation_name        VARCHAR(255),
  ADD COLUMN IF NOT EXISTS organisation_description TEXT;
