connect_error) { die("Connection failed: " . $conn->connect_error . "\n"); } echo "Connected to database successfully.\n"; // Check if table exists $tableCheck = $conn->query("SHOW TABLES LIKE 'ticket_dependencies'"); if ($tableCheck->num_rows > 0) { echo "Table 'ticket_dependencies' already exists.\n"; $conn->close(); exit(0); } // Create the table $sql = "CREATE TABLE 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') NOT NULL DEFAULT 'blocks', created_by INT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (ticket_id) REFERENCES tickets(ticket_id) ON DELETE CASCADE, FOREIGN KEY (depends_on_id) REFERENCES tickets(ticket_id) ON DELETE CASCADE, FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL, 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), INDEX idx_dependency_type (dependency_type) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"; if ($conn->query($sql) === TRUE) { echo "Table 'ticket_dependencies' created successfully.\n"; } else { echo "Error creating table: " . $conn->error . "\n"; } $conn->close();