-- =====================================================================
--  RETAIL PHARMACY PLATFORM
--  Schema Pack T — Erasure marker v1.0
--
--  Apply AFTER schema-phase0-core-v1.sql.
--
--  DPDP Act 2023 gives a person the right to have their data erased.
--  `consent_event` already carried ERASURE_REQUESTED in its enum and no
--  route ever wrote it — consent was recorded nowhere and erasure was
--  impossible.
--
--  This column is the state, not the event. The event says a request was
--  made; the flag says the record has been anonymised, and every read
--  path can honour it cheaply without joining a log.
-- =====================================================================

SET NAMES utf8mb4;

ALTER TABLE customer
  ADD COLUMN is_erased TINYINT(1) NOT NULL DEFAULT 0 AFTER consent_source,
  ADD KEY ix_customer_erased (tenant_id, is_erased);

-- =====================================================================
--  WHAT ERASURE DOES NOT TOUCH, and why:
--
--  The BILLS stay. A dispensing record for a Schedule H drug must be
--  retained under the Drugs and Cosmetics Rules, and a GST invoice must
--  be kept for years. Those obligations do not end because the customer
--  asks — so the PERSON is anonymised and the TRANSACTION survives with
--  nobody attached.
--
--  Pretending otherwise would leave a chemist compliant with one law and
--  in breach of two others.
-- =====================================================================
