-- ===================================================================
-- social_account 테이블에 connected_at, created_at 컬럼 추가 마이그레이션
-- 생성일: 2026-02-03
-- ===================================================================

-- 1. created_at 컬럼 추가 (없는 경우)
ALTER TABLE social_account
ADD COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '생성 일시';

-- 2. connected_at 컬럼 추가
ALTER TABLE social_account
ADD COLUMN connected_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '연결 일시' AFTER is_deleted;

-- 3. 기존 데이터의 connected_at을 created_at 또는 updated_at 값으로 설정
UPDATE social_account
SET connected_at = COALESCE(created_at, updated_at, NOW())
WHERE connected_at IS NULL;

-- ===================================================================
-- 확인 쿼리 (실행 후 검증용)
-- ===================================================================
-- DESCRIBE social_account;
-- SELECT id, platform, connected_at, created_at, updated_at FROM social_account;
