CREATE TABLE IF NOT EXISTS notifications (
    id         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    uuid       CHAR(36)        NOT NULL,
    user_id    BIGINT UNSIGNED NOT NULL,
    type       VARCHAR(50)     NOT NULL,
    title      VARCHAR(255)    NOT NULL,
    body       TEXT            DEFAULT NULL,
    data       JSON            DEFAULT NULL,
    is_read    TINYINT(1)      DEFAULT 0,
    read_at    DATETIME        DEFAULT NULL,
    sent_push  TINYINT(1)      DEFAULT 0,
    created_at DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uq_uuid (uuid),
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
    INDEX idx_user_unread (user_id, is_read),
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
