CREATE TABLE IF NOT EXISTS user_social_accounts (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    user_id BIGINT NOT NULL,
    provider VARCHAR(50) NOT NULL,
    open_id VARCHAR(100) NOT NULL,
    union_id VARCHAR(100) NULL,
    nickname VARCHAR(100) NULL,
    avatar VARCHAR(500) NULL,
    gender VARCHAR(10) NULL,
    email VARCHAR(100) NULL,
    phone VARCHAR(20) NULL,
    extra JSON NULL,
    status INT NOT NULL DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uk_provider_open_id (provider, open_id),
    KEY idx_social_accounts_user_id (user_id),
    CONSTRAINT fk_social_accounts_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
