-- 기존 DB에 회원가입 역할 승인 요청 테이블 추가
-- 실행 예:
-- mysql -h 127.0.0.1 -P 3306 -u jongryangje -p jongryangje_dev < writable/database/member_approval_request_add.sql

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `member_approval_request` (
  `mar_idx`             INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '승인요청 PK',
  `mb_idx`              INT UNSIGNED NOT NULL COMMENT '회원 FK(member.mb_idx)',
  `mar_requested_level` TINYINT UNSIGNED NOT NULL COMMENT '요청 역할(1,2,3)',
  `mar_status`          VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT 'pending|approved|rejected',
  `mar_request_note`    VARCHAR(255) NOT NULL DEFAULT '' COMMENT '요청 메모',
  `mar_reject_reason`   VARCHAR(255) NULL DEFAULT NULL COMMENT '반려 사유',
  `mar_requested_at`    DATETIME NOT NULL COMMENT '요청일시',
  `mar_requested_by`    INT UNSIGNED NULL DEFAULT NULL COMMENT '요청자 mb_idx',
  `mar_processed_at`    DATETIME NULL DEFAULT NULL COMMENT '처리일시',
  `mar_processed_by`    INT UNSIGNED NULL DEFAULT NULL COMMENT '처리자 mb_idx',
  PRIMARY KEY (`mar_idx`),
  KEY `idx_mar_mb_idx` (`mb_idx`),
  KEY `idx_mar_status_requested` (`mar_status`, `mar_requested_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='회원가입 역할 승인 요청';

