-- SheListens — migration 008: real, editable billing intervals for plans
-- Run via phpMyAdmin or: mysql -u USER -p DBNAME < migrations/008_plan_billing_interval.sql
-- Safe to run on an existing database.
--
-- Until now, `period_label` was display text only ("/mo") — the actual
-- renewal date was computed from a hardcoded switch on the plan's id
-- (weekly/monthly/yearly) in subscriptions/select.php. That meant there
-- was no way to actually change how often a plan bills, only what its
-- price tag *said*. This adds real interval fields that drive renewal
-- dates, seeded to match each plan's current behaviour exactly (so
-- nothing changes until an admin edits it).

ALTER TABLE plans
  ADD COLUMN IF NOT EXISTS interval_count INT NOT NULL DEFAULT 1 AFTER video_included,
  ADD COLUMN IF NOT EXISTS interval_unit ENUM('day','week','month','year') NOT NULL DEFAULT 'month' AFTER interval_count;

UPDATE plans SET interval_count = 1, interval_unit = 'week' WHERE id = 'weekly';
UPDATE plans SET interval_count = 1, interval_unit = 'month' WHERE id = 'monthly';
UPDATE plans SET interval_count = 1, interval_unit = 'year' WHERE id = 'yearly';
