-- Migration 001 — "activate or be removed" policy for members who never subscribe.
-- Only needed if you imported db/schema.sql BEFORE this feature existed.
-- Fresh installs get these columns from schema.sql already.
--
-- Import via phpMyAdmin, or: mysql -u USER -p DB < db/migrations/001_pending_policy.sql

ALTER TABLE `groups`
  ADD COLUMN `pending_nudge_days`  VARCHAR(64) NOT NULL DEFAULT '3,6' AFTER `welcome_enabled`,
  ADD COLUMN `pending_remove_days` INT         NOT NULL DEFAULT 7     AFTER `pending_nudge_days`;

ALTER TABLE `members`
  ADD COLUMN `last_pending_nudge` INT DEFAULT NULL AFTER `last_reminder_day`;

-- SAFETY: give everyone who is currently unactivated a fresh 7-day window.
-- Without this, members who joined weeks ago would all be removed on the very
-- first cron run after deploying, because their joined_at is already past the
-- deadline. This only touches never-activated members, whose joined_at is not
-- used for anything else.
UPDATE `members` SET `joined_at` = NOW() WHERE `status` = 'pending';
