-- Casadoc Mobile API - account, profile and document-title features.

-- 6-digit e-mail verification codes (sha256 of the code, never the code itself).
CREATE TABLE IF NOT EXISTS auth_email_verifications (
    email      VARCHAR(191)    NOT NULL,
    token      VARCHAR(191)    NOT NULL,
    attempts   TINYINT UNSIGNED NOT NULL DEFAULT 0,
    created_at TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Same attempt limiting for password reset codes.
ALTER TABLE auth_password_resets
    ADD COLUMN attempts TINYINT UNSIGNED NOT NULL DEFAULT 0;

-- User-defined display name for an uploaded file.
ALTER TABLE doc_storage
    ADD COLUMN title VARCHAR(255) NULL AFTER document_id;
