-- =====================================================================
-- migrate-add-entry-date.sql
-- Adds an "Entry Date" column to the facility mapping and propagates it
-- into collection_raw (looked up by visit_id, exactly like `facility`).
--
-- The column is added in the SAME position on each live table AND its
-- *_stage twin so the atomic "INSERT INTO live SELECT * FROM stage" swap
-- stays column-aligned.
--
-- Fresh installs already include these columns (see collection-dashboard.sql);
-- run this only to upgrade an existing database.
-- =====================================================================

ALTER TABLE `facility_mappings`       ADD COLUMN `entry_date` DATE NULL AFTER `facility`;
ALTER TABLE `facility_mappings_stage` ADD COLUMN `entry_date` DATE NULL AFTER `facility`;
ALTER TABLE `collection_raw`          ADD COLUMN `entry_date` DATE NULL AFTER `facility`;
ALTER TABLE `collection_raw_stage`    ADD COLUMN `entry_date` DATE NULL AFTER `facility`;
