CREATE TABLE IF NOT EXISTS ticket_attachments (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    ticket_id INTEGER NOT NULL,
    kind TEXT NOT NULL CHECK (kind IN ('file', 'link')),
    title TEXT NOT NULL DEFAULT '',
    external_url TEXT NULL,
    provider TEXT NOT NULL DEFAULT 'generic',
    storage_name TEXT NULL,
    original_name TEXT NULL,
    mime_type TEXT NULL,
    size_bytes INTEGER NULL,
    created_by TEXT NOT NULL,
    created_at_ms INTEGER NOT NULL,
    FOREIGN KEY (ticket_id) REFERENCES tickets (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_ticket_attachments_ticket ON ticket_attachments (ticket_id);
