-- 1. users 테이블에 level 추가 (이미 했다면 스킵);
ALTER TABLE users ADD COLUMN level TINYINT NOT NULL DEFAULT 1 COMMENT '0=차단,1=신규,2=일반,10=최고';

-- 2. items 테이블 (메인)
CREATE TABLE IF NOT EXISTS items (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id VARCHAR(100) NOT NULL,
  title VARCHAR(255) DEFAULT '',
  url TEXT NOT NULL,
  image TEXT,
  description TEXT,
  sort_order INT DEFAULT 0,
  is_soft_deleted TINYINT DEFAULT 0 COMMENT '1=삭제(C에게 안보임)',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX(user_id),
  INDEX(is_soft_deleted)
);

-- 3. connected_accounts (이미 있으면 스킵);
CREATE TABLE IF NOT EXISTS connected_accounts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id VARCHAR(100),
  provider VARCHAR(30),
  provider_user_id VARCHAR(100),
  name VARCHAR(255),
  access_token TEXT,
  expires_at DATETIME NULL,
  parent_id VARCHAR(100) NULL,
  UNIQUE KEY uniq (user_id, provider, provider_user_id)
);

-- 4. 너를 최고관리자로 (이메일 수정해서 실행)
-- UPDATE users SET level=10 WHERE email='your_email@gmail.com';

-- 5. 테스트용 조회
-- SELECT id,email,level FROM users;
-- SELECT * FROM items WHERE is_soft_deleted=0;
