-- RAIET v1.30 — BLOCK / SAFETY FOUNDATION
-- Run once after 013_friends_invites.sql.

CREATE TABLE IF NOT EXISTS user_blocks (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    blocker_user_id BIGINT UNSIGNED NOT NULL,
    blocked_user_id BIGINT UNSIGNED NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uq_user_blocks_pair (blocker_user_id, blocked_user_id),
    KEY idx_user_blocks_blocked (blocked_user_id, blocker_user_id),
    CONSTRAINT fk_user_blocks_blocker FOREIGN KEY (blocker_user_id) REFERENCES users(id) ON DELETE CASCADE,
    CONSTRAINT fk_user_blocks_blocked FOREIGN KEY (blocked_user_id) REFERENCES users(id) ON DELETE CASCADE,
    CONSTRAINT chk_user_blocks_not_self CHECK (blocker_user_id <> blocked_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
