-- Migration: Create ticket dependencies table
-- Version: 015

CREATE TABLE IF NOT EXISTS ticket_dependencies (
    dependency_id INT AUTO_INCREMENT PRIMARY KEY,
    ticket_id VARCHAR(9) NOT NULL,
    depends_on_id VARCHAR(9) NOT NULL,
    dependency_type ENUM('blocks', 'blocked_by', 'relates_to', 'duplicates') DEFAULT 'blocks',
    created_by INT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY unique_dependency (ticket_id, depends_on_id, dependency_type),
    INDEX idx_ticket_id (ticket_id),
    INDEX idx_depends_on_id (depends_on_id),
    FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
