-- Add trial configuration to plans table
ALTER TABLE plans
  ADD COLUMN IF NOT EXISTS is_trial BOOLEAN NOT NULL DEFAULT false,
  ADD COLUMN IF NOT EXISTS trial_days INTEGER NOT NULL DEFAULT 0;

-- Add trial consumption tracking to users table (prevents trial abuse)
ALTER TABLE users
  ADD COLUMN IF NOT EXISTS trial_used_at TIMESTAMP;

-- Add trial Ends timestamp to user_subscriptions (declared in schema but never migrated)
ALTER TABLE user_subscriptions
  ADD COLUMN IF NOT EXISTS trial_ends_at TIMESTAMP;

-- Mark the existing 'free' plan explicitly as non-trial (safety)
UPDATE plans SET is_trial = false WHERE name = 'free';