-- Capsule unlock rules + recipients list (MySQL)

ALTER TABLE capsules
  ADD COLUMN unlock_mode ENUM('scheduled','death_threshold') NULL AFTER paid_at,
  ADD COLUMN unlock_at DATETIME NULL AFTER unlock_mode,
  ADD COLUMN unlock_threshold INT NULL AFTER unlock_at,
  ADD KEY idx_capsules_user_id_unlock_mode (user_id, unlock_mode),
  ADD KEY idx_capsules_unlock_at (unlock_at);

CREATE TABLE IF NOT EXISTS capsule_recipients (
  id CHAR(36) PRIMARY KEY,
  capsule_id CHAR(36) NOT NULL,
  email VARCHAR(320) NOT NULL,
  name VARCHAR(255) NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  deleted_at DATETIME NULL,

  UNIQUE KEY uq_capsule_recipients_capsule_email (capsule_id, email),
  KEY idx_capsule_recipients_capsule_id (capsule_id),
  KEY idx_capsule_recipients_email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

