-- Ticket attachments: uploaded files + external links (incl. Google URLs).
-- mysql -u root -p androidcast_crashes < sql/migrations/005_ticket_attachments.sql

CREATE TABLE IF NOT EXISTS ticket_attachments (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    ticket_id BIGINT UNSIGNED NOT NULL,
    kind ENUM('file', 'link') NOT NULL,
    title VARCHAR(256) NOT NULL DEFAULT '',
    external_url TEXT NULL,
    provider VARCHAR(32) NOT NULL DEFAULT 'generic',
    storage_name VARCHAR(128) NULL,
    original_name VARCHAR(256) NULL,
    mime_type VARCHAR(128) NULL,
    size_bytes BIGINT UNSIGNED NULL,
    created_by VARCHAR(64) NOT NULL,
    created_at_ms BIGINT NOT NULL,
    KEY idx_ticket_attachments_ticket (ticket_id),
    KEY idx_ticket_attachments_created (created_at_ms),
    CONSTRAINT fk_ticket_attachments_ticket FOREIGN KEY (ticket_id) REFERENCES tickets (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
