diff --git a/src/main/resources/sports.sql b/src/main/resources/sports.sql new file mode 100644 index 0000000000000000000000000000000000000000..eb401e775ab0876f563854fec266c6e8b4856ce2 --- /dev/null +++ b/src/main/resources/sports.sql @@ -0,0 +1,98 @@ +CREATE DATABASE IF NOT EXISTS sports; +USE sports; +drop table if exists match_item; +drop table if exists ranking; +drop table if exists information; +drop table if exists images; +CREATE TABLE information ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) UNIQUE NOT NULL, + email VARCHAR(50) UNIQUE NOT NULL, + password VARCHAR(255) NOT NULL, + role VARCHAR(20) DEFAULT 'USER' NOT NULL +); +create table if not exists match_item ( + -- Match ID + id BIGINT AUTO_INCREMENT PRIMARY KEY, + -- Sport type + sport ENUM('Pools', 'Darts', 'TableTennis') NOT NULL, + -- Player A ID + player_AId INT NULL, + -- Player B ID + player_BId INT NULL, + plan_Time DATETIME NOT NULL, + -- Match status + status ENUM('pending', 'confirmed', 'completed') DEFAULT 'pending', + score_a INT DEFAULT 0, + score_b INT DEFAULT 0, + confirm_a BOOLEAN DEFAULT FALSE, + confirm_b BOOLEAN DEFAULT FALSE, + winner_id BIGINT DEFAULT NULL +# FOREIGN KEY (player_AId) REFERENCES information(id) ON DELETE CASCADE, +# FOREIGN KEY (player_BId) REFERENCES information(id) ON DELETE CASCADE +# FOREIGN KEY (player_AId) REFERENCES information(id) ON DELETE SET NULL, +# FOREIGN KEY (player_BId) REFERENCES information(id) ON DELETE SET NULL + ); + + +CREATE TABLE IF NOT EXISTS ranking ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, + sport ENUM('Pools', 'Darts', 'TableTennis') NOT NULL, + wins INT DEFAULT 0, + username VARCHAR(255) DEFAULT NULL, + UNIQUE (user_id, sport) -- 添加唯一约束 +); +CREATE TABLE images ( + id INT AUTO_INCREMENT PRIMARY KEY, + url VARCHAR(255) NOT NULL, -- 图片文件名或路径 + uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP-- 上传时间 +); +delete from information; +delete from match_item; +delete from ranking; +INSERT INTO information (id, username, email, password, role) +VALUES (1, 'shy', 'shy@creditsafe.com', '$2a$16$R0aSGzbklUhpRfIMhocewephgUDMFOffLb7faSwwHusqHh81G026i', 'USER'); +INSERT INTO information (id, username, email, password, role) +VALUES (2, 'zyb', 'zyb@creditsafe.com', '$2a$16$R0aSGzbklUhpRfIMhocewephgUDMFOffLb7faSwwHusqHh81G026i', 'USER'); +INSERT INTO information (id, username, email, password, role) +VALUES (3, 'xzc', 'xzc@creditsafe.com', '$2a$16$R0aSGzbklUhpRfIMhocewephgUDMFOffLb7faSwwHusqHh81G026i', 'USER'); +INSERT INTO information (id, username, email, password, role) +VALUES (4, 'xx', 'xx@creditsafe.com', '$2a$16$R0aSGzbklUhpRfIMhocewephgUDMFOffLb7faSwwHusqHh81G026i', 'USER'); +insert into match_item (sport, player_AId, player_BId, plan_Time, status, score_a, score_b, confirm_a, confirm_b, winner_id) +values +-- test data +-- 1: Pending status + ('Pools', 1, 2, '2024-11-25 14:30:00', 'pending', 0, 0, FALSE, FALSE, NULL), +-- 2: Confirmed status, Player 3 wins + ('Darts', 3, 4, '2024-11-26 16:00:00', 'confirmed', 3, 2, TRUE, TRUE, 3), +-- 3: Completed status, Player 6 wins + ('TableTennis', 1, 2, '2024-11-27 18:00:00', 'completed', 21, 18, TRUE, TRUE, 2), +-- 4: Pending status + ('Pools', 2, 1, '2024-11-28 20:00:00', 'pending', 0, 0, FALSE, FALSE, NULL), +-- 5: Completed status, Player 9 wins + ('Darts', 1, 2, '2024-11-29 15:30:00', 'completed', 300, 280, TRUE, TRUE, 2), +-- 6: Confirmed status, Player 1 wins + ('TableTennis', 1, 2, '2024-11-30 17:00:00', 'confirmed', 3, 1, TRUE, TRUE, 1), + ('TableTennis', null, null, '2024-12-20 17:00:00', 'pending', 0, 0, false, false, null), + ('TableTennis', null, null, '2024-12-21 17:00:00', 'pending', 0, 0, false, false, null), + ('Pools', null, null, '2024-12-22 17:00:00', 'pending', 0, 0, false, false, null), + ('Pools', null, null, '2024-12-23 17:00:00', 'pending', 0, 0, false, false, null), + ('Pools', null, null, '2024-12-24 17:00:00', 'pending', 0, 0, false, false, null), + ('Darts', null, null, '2024-12-25 17:00:00', 'pending', 0, 0, false, false, null), + ('Darts', null, null, '2024-12-26 17:00:00', 'pending', 0, 0, false, false, null), + ('Darts', null, null, '2024-12-27 17:00:00', 'pending', 0, 0, false, false, null); +INSERT INTO ranking (user_id,username,sport, wins) VALUES + (1, 'shy','Pools', 0), + (1, 'shy','Darts', 0), + (1, 'shy','TableTennis', 0), + (2, 'zyb','Pools', 0), + (2, 'zyb','Darts', 0), + (2, 'zyb','TableTennis', 0), + (3, 'xzc','Pools', 0), + (3, 'xzc','Darts', 0), + (3, 'xzc','TableTennis', 0), + (4, 'xx','Pools', 0), + (4, 'xx','Darts', 0), + (4, 'xx','TableTennis', 0); +