-- Track when submodule lessons, practices, and capstones became inactive for retention-based hard delete.

ALTER TABLE sub_module_lessons
    ADD COLUMN IF NOT EXISTS inactive_since TIMESTAMPTZ;

ALTER TABLE sub_module_practices
    ADD COLUMN IF NOT EXISTS inactive_since TIMESTAMPTZ;

ALTER TABLE sub_module_capstones
    ADD COLUMN IF NOT EXISTS inactive_since TIMESTAMPTZ;

-- Existing inactive rows: start retention window from migration time (conservative).
UPDATE sub_module_lessons
SET inactive_since = NOW()
WHERE is_active = FALSE
  AND inactive_since IS NULL;

UPDATE sub_module_practices
SET inactive_since = NOW()
WHERE is_active = FALSE
  AND inactive_since IS NULL;

UPDATE sub_module_capstones
SET inactive_since = NOW()
WHERE is_active = FALSE
  AND inactive_since IS NULL;
