Skip to content
Snippets Groups Projects
Commit ae7b1fcb authored by Haoyu Sun's avatar Haoyu Sun
Browse files

adjust database

parent f39970e2
Branches
No related tags found
1 merge request!54Resolve "As an administrator, I want to generate the matches automatically so that players are divided by the program"
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
......@@ -14,10 +23,18 @@ values
-- 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', 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, 'xzc','Pools', 5),
(2, 'shy','Darts', 3),
(3, 'xx','TableTennis', 10),
(2, 'shy','TableTennis', 4);
(1, 'shy','Pools', 5),
(2, 'zyb','Darts', 3),
(3, 'xzc','TableTennis', 10),
(2, 'xx','TableTennis', 4);
drop table if exists match_item;
drop table if exists rankings;
drop table if exists information;
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 BIGINT NOT NULL,
player_AId INT NULL,
-- Player B ID
player_BId BIGINT NOT NULL,
player_BId INT NULL,
plan_Time DATETIME NOT NULL,
-- Match status
status ENUM('pending', 'confirmed', 'completed') DEFAULT 'pending',
......@@ -16,16 +24,14 @@ create table if not exists match_item (
score_b INT DEFAULT 0,
confirm_a BOOLEAN DEFAULT FALSE,
confirm_b BOOLEAN DEFAULT FALSE,
winner_id BIGINT DEFAULT NULL
);
drop table if exists information;
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
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
);
drop table if exists ranking;
CREATE TABLE IF NOT EXISTS ranking (
id INT AUTO_INCREMENT PRIMARY KEY,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment