34233-vm/db/migrations/001_initial_schema.sql
Flatlogic Bot 4feeb6dacd v2
2025-09-19 20:26:26 +00:00

24 lines
776 B
SQL

CREATE TABLE IF NOT EXISTS `teams` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS `tournaments` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`start_date` DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `matches` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`tournament_id` INT NOT NULL,
`round` INT NOT NULL,
`team1_id` INT,
`team2_id` INT,
`winner_id` INT,
FOREIGN KEY (`tournament_id`) REFERENCES `tournaments`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`team1_id`) REFERENCES `teams`(`id`) ON DELETE SET NULL,
FOREIGN KEY (`team2_id`) REFERENCES `teams`(`id`) ON DELETE SET NULL,
FOREIGN KEY (`winner_id`) REFERENCES `teams`(`id`) ON DELETE SET NULL
);