-- Migration: Create tournament_pairing table
-- Date: 2025-01-23
-- For MariaDB/MySQL

CREATE TABLE IF NOT EXISTS `tournament_pairing` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `tournament_id` INT(11) NOT NULL,
  `class_id` INT(11) NOT NULL,
  `group_id` INT(11) NULL,
  `member1_id` INT(11) NULL,
  `external1_id` INT(11) NULL,
  `member2_id` INT(11) NULL,
  `external2_id` INT(11) NULL,
  `seeded` TINYINT(1) NOT NULL DEFAULT 0,
  `created_at` DATETIME NOT NULL,
  `updated_at` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `tournament_id` (`tournament_id`),
  KEY `class_id` (`class_id`),
  KEY `group_id` (`group_id`),
  KEY `member1_id` (`member1_id`),
  KEY `member2_id` (`member2_id`),
  KEY `external1_id` (`external1_id`),
  KEY `external2_id` (`external2_id`),
  CONSTRAINT `tournament_pairing_ibfk_1` FOREIGN KEY (`tournament_id`) REFERENCES `tournament` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `tournament_pairing_ibfk_2` FOREIGN KEY (`class_id`) REFERENCES `tournament_class` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `tournament_pairing_ibfk_3` FOREIGN KEY (`group_id`) REFERENCES `tournament_group` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;





