-- Tracks which ordinal version of a section lineage was archived and the lineage root,
-- consistent with orac_form_details versioning (recursive parent chain).

ALTER TABLE `orac_archive_section`
  ADD COLUMN `section_version` int NOT NULL DEFAULT 1 AFTER `archived_at`,
  ADD COLUMN `version_root_id` int DEFAULT NULL AFTER `section_version`,
  ADD KEY `orac_archive_section_version_root` (`version_root_id`),
  ADD CONSTRAINT `orac_section_details_orac_archive_section_root`
    FOREIGN KEY (`version_root_id`) REFERENCES `orac_section_details` (`section_id`)
    ON DELETE SET NULL ON UPDATE CASCADE;
